Search code examples
c#asp.netcsscode-behind

Changing the CSS in code behind asp.net


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?


Solution

  • 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");