I have a <div> element that I want to dynamically add some HTML <a> elements to. That part seems to be working just fine. Here is the HTML:
<div id="crumbBar" runat="server"/>
In my code behind, adding HTML anchors works as expected; however, when the page renders, the id is changed to ‘workArea_crumbBar’ (this is all in a master page).
I tried dynamically creating a <div> within the <div> with the appropriate id, but that also prepended the id with ‘workarea_’.
I’ve got other code that relies on the id of the <div> element. Is there some way to keep IIS from changing the id of either the main or nested element?
Try to change your div like this:
In fact, this is not IIS but the ASP.Net Framework behavior. The controls are organized in a tree, and the final client id will be the result of the concatenation of the all the ancestors IDs.
The goal is to avoid conflicting Id between two controls. An example of conflict is when you create a user control with, for example:
<asp:label id="mylbl" runat="server" />. If you instantiate twice the user control, two controls will have the same Id on the client side without this behavior.That mean you have to use precautiously this attribute, at it can lead to some obscure issues. You should looks for another solution if you can. After 12 years of building .Net apps, I never have to use this attribute. There are probably alternatives.