Solved

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

Posted on 2009-07-04
4
1,296 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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

763 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