开发者

Problem regarding master pages

开发者 https://www.devze.com 2023-02-20 15:38 出处:网络
I have a simple master page (master.aspx), which has 3 link buttons namely HomeLBTn-which redirects the users to home.aspx, LoginLBtn-to login.aspx, RegisterLBtn-to Register.aspx

I have a simple master page (master.aspx), which has 3 link buttons namely HomeLBTn-which redirects the users to home.aspx, LoginLBtn-to login.aspx, RegisterLBtn-to Register.aspx

Every page in my project inherits the master page. And home.aspx also inherits the master.aspx, but i don't want the home.aspx to inheri开发者_运维百科t the HomeLBtn, I want it to inherit the remaining 2 LBtn's, but not the HomeLBtn. How can i incorporate this condition into Home.aspx

Please help me

Thanks in anticipation


One way would be to find the control in the MasterPage and set its visibility to false:

Page.Master.FindControl("HomeLBtn").Visible = False

This would be done in the Page_Load (or some other lifecycle event) on the page that shouldn't show the Home button.


In master.aspx, define Register and Login link buttons, and a content placeholder for where the Home button would go. Then have Home.aspx inherit master.aspx. Then create a 2nd master page (master2.aspx) that inherits from master.aspx. In master2, add the Home link button in the content placeholder, and have your other pages inherit from master2.


You can do something like this in the master page ( Check what the child page is )

 //If the child page is viewing an order then disable the new request button       
 if (this.ContentPlaceHolder1.Page is OrderView)       
 { 
      base.RemoveMenuItem("New Request", mnuSettings);        
 }

Note: base.RemoveMenuItem is a method of my base page

http://wraithnath.blogspot.com/2010/09/how-to-hide-show-controls-on-master.html

Another option would be to add a property to the child page and master page and use session data to hide and show buttons.

eg. in Child Page:

protected MyCustomMasterPage CustomMasterPage
{
  get
  {
     return this.Master as MyCustomMasterPage;
  }
}

In your master page you could have a session variable you can set to hide and show the buttons

public bool HomeVisible
{
   get
   {
      return (bool) Session["HomeVisible"]; 
   }
   set
   {
      Session["HomeVisible"] = value;
   }
}

You would then check the HomeVisible property when loading the master page to show / hide the button. You can then set this from the child page.

this.MyCustomMasterPage.HomeVisible = false;

Maybe not the best ways but they work

0

精彩评论

暂无评论...
验证码 换一张
取 消