Link to home
Start Free TrialLog in
Avatar of SGIC2008
SGIC2008

asked on

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

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
Avatar of nasserd
nasserd
Flag of United States of America image

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.
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 + "')")
ASKER CERTIFIED SOLUTION
Avatar of nikege
nikege

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SGIC2008
SGIC2008

ASKER

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.