Since I’ve got into ASP.NET I have found loads of really cool features, which in the main make the programming much easier.
I’m struggling with one aspect though.
If I create a User Control which has loads of Javascript functions associated with it, when the User Control is rendered, .NET changes the IDs of everything with a prepended value depending on the name of the User Control, it’s containing PlaceHolder and the ID of the MasterPage.
Obviously this stops any javascript which is ID dependant from working properly.
I can get round this by manually changing the references in the javascript, but what if I want to put this content into a different placeHolder?
Is there a way to dynamically overcome this issue?
There’s a couple of things you can do, you could inject the control name into your JavaScript using the
ClientIDproperty like this –or in .net 4 you can control the naming of controls via the
ClientIDModeproperty, there are further details in this article – https://web.archive.org/web/20211020203215/https://www.4guysfromrolla.com/articles/031710-1.aspx