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?

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. Commented Dec 13, 2012 at 21:59

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.