Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

why do my Control IDs suddenly reference "_ctl0" in ASP.NET?

Posted on 2009-07-04
4
Medium Priority
?
1,329 Views
Last Modified: 2013-11-18
Hello All,

I have a web application in ASP.NET that uses a master page as a template.

Everything works fine in our development environment, but when we deploy the application to the production environment all of the control IDs change:

For example, this on development:
<input name="ctl00$cphMainContent$txtSomeTextbox" type="text" id="ctl00_cphMainContent_txtSomeTextbox" />

Becomes this on release:
<input name="_ctl0:cphMainContent:txtSomeTextbox" type="text" id="_ctl0_cphMainContent_txtSomeTextbox" />

The application uses javascript on numerous pages to access elements via the 'getDocumentById' function, so having the IDs changes in the source like this is buggering things up quite a bit.  The server is configured the same for .NET for both environments.

Has anyone else also seen this behavior?  What is cause and how do I go about fixing it so that the IDs do not change in the source?

Many thanks,

pvirk
0
Comment
Question by:SGIC2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 4

Expert Comment

by:nasserd
ID: 24778318
ASP.NET Web Controls have this known "translation" of ControlID's between WYSIWYG and deployed states.  It is an intentional and well documented behavior.

HTML Web Controls, however, do not change their ControlID's between edit and published views.
0
 
LVL 10

Expert Comment

by:Espavo
ID: 24779026
This is "standard" behavior of ASP.Net...
You can use txtSome.ClienID to get the "Server Control ID at RunTime" and you can then pass that info to your JavaScript...
Here's an example of how I use it:
KeywordTB.Attributes.Add("onKeyPress", "doClick('" + KwdSrchBtn.ClientID + "')")
0
 
LVL 2

Accepted Solution

by:
nikege earned 2000 total points
ID: 24780739
Check web.confing on both servers.It seems one of them contains

<xhtmlConformance mode="Legacy"/>

Look at this article http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx.
 here is the result of using and not using Legacy

With legacy, this is the emitted html:

           <input id="_ctl0__ctl0_eDefaultStore_0" type="radio" name="_ctl0:_ctl0:eDefaultStore" value="1" />

Without legacy:

           <input id="ctl00_ctl00_eDefaultStore_0" type="radio" name="ctl00$ctl00$eDefaultStore" value="1" />
0
 

Author Closing Comment

by:SGIC2008
ID: 31599829
Thanks this was exactly what the problem was.  The root web.config had this set to legacy and this was inherited by our application that was in a sub folder.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question