I'm trying to modify a CSS style attribute for a div based on the information I get from a database table in the code behind of my aspx page. The following is essentially what I am trying to do, but I get errors.
Aspx:
<div id="testSpace" runat="server"> Test </div>
Code Behind:
testSpace.Style = "display:none;" testSpace.Style("display") = "none";
What am I doing wrong?
If your div has runat="server" then you directly use this: divAllItemList. Attributes["class"] = "hidden"; Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM.
If you want to add attributes, including the class, you need to set runat="server" on the tag. Thanks, I was sure it would be this simple. @Tyler, no. This adds a new class name to the control.
CSS style can be applied from code behind by accessing the properties of the control with the help of its Id. Most of the CSS styles can be applied using the Font property and its sub properties however you can use ForeColor and BackColor directly also.
If you want to find the control from code behind you have to use runat="server" attribute on control. And then you can use Control. FindControl . If you use runat server and your control is inside the ContentPlaceHolder you have to know the ctrl name would not be portlet_tab1 anymore.
testSpace.Style.Add("display", "none");
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