Two questions: Master pages and navigation
-
1. How do I switch between 2 master pages for the same content page? For example: one master page for a logged in user and a different one for a visitor. 2. In a function in a code-behind page in c#, how do I navigate back one page, like in the "Back" button of the browser?
-
1. How do I switch between 2 master pages for the same content page? For example: one master page for a logged in user and a different one for a visitor. 2. In a function in a code-behind page in c#, how do I navigate back one page, like in the "Back" button of the browser?
-
Ad.1 You can set the MasterPage file in PreInit event. 2. What exactly would you like to do?
1. Using Visual Web Developer 2005 Express Edition, how do I link a function to the PreInit event? 2. I want to create a button that does a few things, and then redirects the user to the page he was previous to the current page (could be any page).
-
1. Using Visual Web Developer 2005 Express Edition, how do I link a function to the PreInit event? 2. I want to create a button that does a few things, and then redirects the user to the page he was previous to the current page (could be any page).
1.
public partial class Default : System.Web.UI.Page { protected void Page_PreInit() { if(IsPostBack) { this.MasterPageFile = "MasterPage2.master"; } } protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { //Call some event to cause page reload } }
I'm not sure that is what you are looking, but remember the ID ContentPlaceHolder in Master1 and Master2 must be the same. 2. You can send a adres of previous page in hidden field or in viewstate or remember in session or in cache. Sorry for my english :) -
1.
public partial class Default : System.Web.UI.Page { protected void Page_PreInit() { if(IsPostBack) { this.MasterPageFile = "MasterPage2.master"; } } protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { //Call some event to cause page reload } }
I'm not sure that is what you are looking, but remember the ID ContentPlaceHolder in Master1 and Master2 must be the same. 2. You can send a adres of previous page in hidden field or in viewstate or remember in session or in cache. Sorry for my english :)Yes, that's what I was looking for. I just have a casting problem: I've put this line on top of the aspx page: <%@ MasterType VirtualPath="~/MainMasterPage.master"%> The problem is that it's good for one of the masterpages (MainMasterPage) and not for the other, and I can put only one line of this type in the page. Without the MasterType line, when I try to do the casting in the code behind page, for example: (UserMasterPage)this.MasterPageFile = "~/UserMasterPage.master"; Then the string on the right side of the equation should be cast to UserMasterPage. Any suggestions?
-
Yes, that's what I was looking for. I just have a casting problem: I've put this line on top of the aspx page: <%@ MasterType VirtualPath="~/MainMasterPage.master"%> The problem is that it's good for one of the masterpages (MainMasterPage) and not for the other, and I can put only one line of this type in the page. Without the MasterType line, when I try to do the casting in the code behind page, for example: (UserMasterPage)this.MasterPageFile = "~/UserMasterPage.master"; Then the string on the right side of the equation should be cast to UserMasterPage. Any suggestions?