Changing the CSS in code behind asp.net
Asked Answered
H

1

5

in my aspx page I have this div..

<div id="downloadableProducts" runat="server"><a href="#">Downloadedable Products</a></div>

I am trying to change the css in the code behind like this..

downloadableProducts.Style("display") = "none";

but this does not work, I get an error and red underline under downloadableProducts in the code behind and it says 'The name 'downloadableProducts' does not exist in the current context '

What am I doing wrong?

Hoplite answered 4/6, 2012 at 19:53 Comment(1)
Also for those who copy this code it won't work straigth out of the box it's missing braces around "display" it should look like this.. downloadableProducts.Style["display"] = "none"; as we are writing C# code.Stomatic
J
13

You need to add runat="server" to the div and access it as a HtmlControl in your codebehind. For example:

HtmlControl div1 = (HtmlControl)Page.FindControl("downloadableProducts");
Jere answered 4/6, 2012 at 19:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.