Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3428488
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:57:54+00:00 2026-05-18T06:57:54+00:00

I have a webform which uses a masterpage which in turn inherits from another

  • 0

I have a webform which uses a masterpage which in turn inherits from another masterpage.

I have a dropdownlist drpCursos

In my javascript code I tried to access the control but with no luck:

var combo = document.forms[0]['drpCursos'];

combo is null

After checking the source code, I changed it to:

var combo = document.forms[0]['ctl00_ContentPlaceHolder1_drpCursos'];

It works now, but I don’t think it’s a good solution…

How would I do this the right way?

EDIT: My javascript code is in an external file.

I tried Darin’s solution but it didn’t work, then I pasted my code directly in the aspx page and now it worked.

Also, it only works when the code is inside a function, otherwise I get undefined

Why does this happen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:57:55+00:00Added an answer on May 18, 2026 at 6:57 am

    Darin’s solution will work, but if you are using .net 4.0 there are possibly better solutions now. Using the ClientIDMode property of the control you can control what names get assigned to the control at run-time (i.e. the ‘ctl00_ContentPlaceHolder1_drpCursos’).

    i.e. <asp:Label ID="Label1" runat="server" ClientIDMode="[Mode Type]"/>

    http://weblogs.asp.net/asptest/archive/2009/01/06/asp-net-4-0-clientid-overview.aspx

    Excerpted below:

    The Mode Types

    • Legacy: The default value if ClientIDMode is not set anywhere in the control hierarchy. This causes client side IDs to behave the way they did in version 2.0 (3.0 and 3.5 did not change this code path) of the framework. This mode will generate an ID similar to “ctl00_MasterPageBody_ctl01_Textbox1.”

    • Inherit: This is the default behavior for every control. This looks to the controls parent to get its value for ClientIDMode. You do not need to set this on every control as it is the default, this is used only when the ClientIDMode has been changed and the new desired behavior is to inherit from the controls parent.

    • Static: This mode does exactly what you think it would, it makes the client side ID static. Meaning that what you put for the ID is what will be used for the client side ID. Warning, this means that if a static ClientIDMode is used in a repeating control the developer is responsible for ensuring client side ID uniqueness.

    • Predictable: This mode is used when the framework needs to ensure uniqueness but it needs to be done so in a predictable way. The most common use for this mode is on databound controls. The framework will traverse the control hierarchy prefixing the supplied ID with it’s parent control ID until it reaches a control in the hierarchy whose ClientIDMode is defined as static. In the event that the control is placed inside a databound control a suffix with a value that identifies that instance will also be added to the supplied ID. The ClientIDRowSuffix property is used to control the value that will be used as a suffix (see samples). This mode will generate an ID similar to “Gridview1_Label1_0”

    If you have just some controls where you need the ID for use with javascript, I would personally use the ‘static’ method, assign ID’s that I want, and let .net assign the rest in the default manner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET webform on which I use a DropDownList control to allow
We have an ASP.NET web application which uses ASP.NET Ajax. We open it from
I have a WebForm before_adm.aspx.cs which has the code as follows: . . .
I have a webform which uses a gridview control to show result of a
I have a webform which has validators on it that work well when the
I have an ASP.NET webform which I want to validate Client-Side and Server-Side, using
I have an ASP.NET page (WebForm) on which I set the content of a
I have in my webform many TBs bound to a property in the code
I have a simple webform which have few text fields,leabels and Submit button. When
I have an button in my Jquery mobile page, which is using asp.net webform.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.