Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Header.master--->page


ASP.NET
<asp:ContentPlaceHolder ID="cntplcDiv" runat="server"
<div runat="server" id="divCmptMenu">
    <ul id="nav">
                <li><asp:HyperLink ID="hypLnkhome" runat="server" NavigateUrl="~/Admin_Home.aspx">Home</asp:HyperLink></li>
                <li><asp:HyperLink ID="hypLnkconfigSettng" runat="server" >Config & Settings</asp:HyperLink>
                    <ul class="subs">
                        <li><asp:HyperLink ID="hypLnkUsrStng" runat="server" NavigateUrl="~/ListUsers.aspx">User Settings</asp:HyperLink></li>
                        <li><asp:HyperLink ID="hypLnkprdStng" runat="server" Text="Production Settings"></asp:HyperLink></li>
                        <li><asp:HyperLink ID="HyperLink1" runat="server" ></asp:HyperLink></li>
                        <li><asp:HyperLink ID="hypLnkEmailTmp" runat="server" >Email Templates</asp:HyperLink></li>
                        <li><asp:HyperLink ID="HyperLink4" runat="server" ></asp:HyperLink></li>
                        <li><asp:HyperLink ID="hypLnkTaxSttng" runat="server" Text="Tax Settings" NavigateUrl="~/TaxSetting.aspx" ></asp:HyperLink></li>
                        <li><asp:HyperLink ID="HyperLink5"  runat="server" ></asp:HyperLink></li>
                    </ul>
                </li>
 </div>
  
<asp:ContentPlaceHolder>


Header.master.cs

C#
protected void Page_Load(object sender, EventArgs e)
    {

CheckForEstPage();

}

    public void CheckForEstPage()
    {
        try
        {
            String path = HttpContext.Current.Request.Url.AbsolutePath;
            System.Web.UI.HtmlControls.HtmlGenericControl currdiv = (System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("divCmptMenu");

            if (path == "~/EstimateForms.aspx")
            {
                currdiv.Style.Add("display", "none");
                // currdiv.Visible = false;
            }

        }
        catch (Exception expM)
        {
            Response.Write(expM.Message);
        }
    }



plz help me with the coding i want to hide the masterpage div in particular webpage(for in ex. estimateform)... i have tried a lot of coding... i am getting error
"Object reference not set to an instance of an object. "
thank u...

What I have tried:

???
Posted
Updated 24-Feb-17 4:46am
v3

You can try this

this.Page.Master.FindControl("Id of control that have runat=server")
 
Share this answer
 
find a master page control from content page like this:-

//your div should contain the property
 runat="server"
 
//finding the div associated with id 
System.Web.UI.HtmlControls.HtmlGenericControl currdiv = (System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("divid");
 
//hiding the div
 currdiv.Style.Add("display", "none");



or try this:-

HtmlGenericControl Divid = (HtmlGenericControl)Page.Master.FindControl("MainDiv").FindControl("Divid");
 Divid.Visible = false;
 
Share this answer
 
v2
Comments
Member 9467059 19-Apr-13 9:01am    
sorry pals still getting same error...
and div is not getting invisible when itz in estimatefrom.aspx...
plz help me with it its urgent
TrushnaK 19-Apr-13 9:06am    
on which line you get error.
Member 9467059 22-Apr-13 1:34am    
protected void Page_Load(object sender, EventArgs e)
{

CheckForEstPage();

}
public void CheckForEstPage()
{
try
{
String path = HttpContext.Current.Request.Url.AbsolutePath;

till executing here its going to catch block..
error"Object reference not set to an instance of an object."
 
Share this answer
 
Hello everybody! Well, in my case, I had two divs inside another one, I had been trying to hide them, so, I used this code and works perfectly:

protected void Page_Load(object sender, EventArgs e)
       {
         var HideDiv= this.Master.FindControl("MainDiv");

           if (HideDiv != null)
           {
               HtmlGenericControl InsideDiv_1 = (HtmlGenericControl)HideDiv.FindControl("InsideDiv1");
               HtmlGenericControl InsideDiv_2 = (HtmlGenericControl)HideDiv.FindControl("InsideDiv2");
               if (InsideDiv_1 != null)
               {
                   InsideDiv_2.Visible = false;
                   InsideDiv_1.Visible = false;
               }
           }
       }
   }


Good Luck.
 
Share this answer
 
Comments
Richard Deeming 24-Feb-17 11:31am    
FOUR YEARS too late.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900