I have the following code:
div1.Attributes.Add("class", "displayNone");
it works on page load but doesn't on an OnClick event.
This is because my html <div id="div1"></div> seems to change to:
<div id="div1_ucSomeControl_SoemthingElse"></div>
after the page has been rendered.
How can I get around this?
I don't think that the ID of the control matters in this case. You may be running into this issue because the class attribute already exists. Try this instead:
div1.Attributes["class"] = "displayNone";
<div id="div1" runat ="server">
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
code behind:
protected void Button1_Click(object sender, EventArgs e)
{
div1.Attributes.Add("class", "displayNone");
}
this will be work.
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