Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Can't create users table in existing DB 16 60
varchar (max) 5 29
Azure Web App - See files 3 21
Entity Framework 3 14
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

10 Experts available now in Live!

Get 1:1 Help Now