|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ID of web control changedHello, I have been developing a website locally for quite some time now
in ASP.NET 2.0/C# and all of the web controls (locally) have IDs like this: ctl00_ContentPlaceHolder1_ddSearchType I just uploaded it to our live site today, for the first time, and now all of my IDs look like this: _ctl0_ContentPlaceHolder1_ddSearchType What gives? My javascript is now all broken because of this. Is there a place where I can specify to use ctl00 instead of _ctl0 ? The only way I can think to fix this is by using a literal (or something) and have c# generate the JS on the fly using the controls UniqueID property, which seems really stupid. It's hundreds of lines of JS. Thanks -Adam You shouldn't rely on the IDs to be in a specific format. Use the ClientID
property to get the ID to use in Javascript. /Guffa Show quoteHide quote "Adam Plocher" wrote: > Hello, I have been developing a website locally for quite some time now > in ASP.NET 2.0/C# and all of the web controls (locally) have IDs like > this: ctl00_ContentPlaceHolder1_ddSearchType > > I just uploaded it to our live site today, for the first time, and now > all of my IDs look like this: > _ctl0_ContentPlaceHolder1_ddSearchType > > What gives? My javascript is now all broken because of this. Is there > a place where I can specify to use ctl00 instead of _ctl0 ? The only > way I can think to fix this is by using a literal (or something) and > have c# generate the JS on the fly using the controls UniqueID > property, which seems really stupid. It's hundreds of lines of JS. > > Thanks > -Adam > > So should I be loading all my JS into a Literal or something? I can't
just write JS code into my aspx or into a standalone .js file? > So should I be loading all my JS into a Literal or something? I can't You have several options. You can either create all of the code dynamically, > just write JS code into my aspx or into a standalone .js file? or just part of it. You can for an example make wrappers for the fields that you need to access: function getSomeField() { return document.getElementById('<asp:Literal id="SomeFieldLiteral" runat="server"/>'); } and in code-behind: SomeFieldLiteral.Text = SomeField.ClientId; You can also create the wrapper entirely frfom code-behind: Page.RegisterClientScriptBlock("GetSomeField", "<script type=\"text/javascript\">function getSomeField() { return document.getElementById('" + SomeField.ClientId + "'); }</script>"); Thanks Guffa, I'll play around with these and see what I come up with.
Add additional navigation buttons to wizard control
.Net Menu controls Custom Panel imagefield in gridview How to upload files to a remote webserver using FileUpload ? MetaBuilders DualList control does not work in 2.0 Auto Download Serial Communication DropdownList fields in DetailView for sale: internetDotComs.com |
|||||||||||||||||||||||