Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now