views:

43

answers:

4

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!

+1  A: 

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
+2  A: 

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.

jelbourn
A: 

In addition to having runat="server" in the div tag, you'll need to expose the div as a public type in your masterpage by placing the following in your masterpage's code behind class public HtmlGenericControl myDivID;.

Then at the top of the aspx page that is using the masterpage, you'll use the MasterType page directive to create a strongly typed reference to your masterpage in the page's code behind: <%@ MasterType VirtualPath="~/PathToMyMasterpage.master”" %>

MSDN reference for MasterType

yorkrj
+2  A: 

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