I have a C# code where I am setting the ID of a DIV.
Example:
div.ID = "slider";
The only issue is when the website loads ASP adds a whole bunch of random characters in front of the ID. I cannot use the <% Page %>
because I am just using a Web Part.
When I tried to set:
div.ClientID = "static";
I am given an error where the property is read only.
Is there any other way to set it within C#, so the ID does not change when the website runs my page?
I do not want to use <%= slider.ClientID %>
in the javascript/css code but if that's the only way then I guess I have no choice.
You are looking for ClientIDMode
property, not ClientID
div.ClientIDMode = System.Web.UI.ClientIDMode.Static;
If you want to define it in aspx page then you can do:
<div id="myDiv" runat="server" ClientIDMode="static" ></div>
Remember it is provided with .Net framework 4.0 and above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With