3

what's the DIV equivalent to this command?

((Panel)this.Page.Master.FindControl("Panel1")).Style.Add("display", "none");

This works great with a panel but I can't find the variation for doing the same thing with a DIV who's ID I know. anyone know?

thanks in advance for the help!

AsifQadri
  • 2,388
  • 1
  • 20
  • 30
korben
  • 53
  • 1
  • 4

3 Answers3

10

Div belongs to HtmlGenericControl class of System.Web.UI.HtmlControls namespace.

((HtmlGenericControl)this.Page.Master.FindControl("divID")).Style.Add("display", "none");

and your your div control in master page sholud be runat="server"

Thanks

Asif

AsifQadri
  • 2,388
  • 1
  • 20
  • 30
2

If the div is runat="server", it is an HttpGenericControl rather than a Panel. If the div is not runat="server", you cannot access it server-side like you would a WebControl.

Jeremy Elbourn
  • 2,630
  • 1
  • 18
  • 15
1

If you want to do this from the server-side code (code-behind), then you just have to add the runat="server" attribute to the DIV:

<div id="myDiv" runat="server">...</div>

Then you access the div the same way as the panel in your example.

M4N
  • 94,805
  • 45
  • 217
  • 260