Linking a page to two Master Pages?

Last post 05-09-2008 3:22 PM by linjitvd. 5 replies.

Sort Posts:

  • Linking a page to two Master Pages?

    05-09-2008, 2:35 PM
    • Loading...
    • md123
    • Joined on 05-07-2008, 8:05 PM
    • Posts 7

    Hi,

     

    What I want is to have a page use a different master page dependant on their user role. There are two buttons that should be available only to users in the "Administrator" group and not those in the "Members" group (the only two groups I have). My buttons are defined the master pages and their graphics provided using CSS, so the simplest way of acheiving what I want that I could see was having the page use the MembersMasterPage.Master if they are a Member or the AdminMasterPage.master if they are an Admin.

    First of all is this possible, if so how do I go about it?

    Much Appreciated

  • Re: Linking a page to two Master Pages?

    05-09-2008, 2:40 PM

     

    I think you would be better off with one master page, not two, for the situation you describe.

    Just have the master page check the user's group and disable/hide the relevant buttons!
     

    If this answered your question, be sure to mark it as the answer. That way, everybody after you will know it's the answer also!
  • Re: Linking a page to two Master Pages?

    05-09-2008, 2:46 PM
    • Loading...
    • JZoerman
    • Joined on 08-24-2006, 6:27 AM
    • Posts 95
    If you want to do it that way you can specify which master page to use for the child page with.

    page.MasterPageFile="master.master"

    Personally I would just use code on a single master page to determine what buttons are available based on the users roles.

  • Re: Linking a page to two Master Pages?

    05-09-2008, 3:00 PM
    • Loading...
    • md123
    • Joined on 05-07-2008, 8:05 PM
    • Posts 7

    Could someone let me know how I would go abour witing that as a procedure so that:

     If Roles.IsUserInRole("Administrator") Then

    <div id="mainmenu"><ul> <li><a href="../AddRecords.aspx">Add Quotes</a></li> <li><a href="ViewQuote.aspx">View Quote</a></li><li><a href="Upload.aspx">Upload New Products</a></li><li><a href="../NewProducts.aspx">New Products</a></li></ul></div>

    elseif Roles.IsUserInRole("Member")  Then

    <div id="mainmenu"><ul> <li><a href="AddRecords.aspx">Add Quotes</a></li><li><a href="NewProducts.aspx">New Products</a></li></ul></div>

    else

    endif

    A procedure which basically does that but that will work.

  • Re: Linking a page to two Master Pages?

    05-09-2008, 3:18 PM
    • Loading...
    • JZoerman
    • Joined on 08-24-2006, 6:27 AM
    • Posts 95

    Here is a very basic example

    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>

    <script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    If User.IsInRole("Administrator") Then

    AddQuotes.Visible = True

    ViewQuote.Visible = True

    UploadNewProducts.Visible = True

    NewProducts.Visible = True

    Else

    AddQuotes.Visible = True

    ViewQuote.Visible = False

    UploadNewProducts.Visible = False

    NewProducts.Visible = True

    End If

    End Sub

    </script>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:HyperLink ID="AddQuotes" runat="server" NavigateUrl="">HyperLink</asp:HyperLink><br />

    <asp:HyperLink ID="ViewQuote" runat="server" NavigateUrl="">HyperLink</asp:HyperLink><br />

    <asp:HyperLink ID="UploadNewProducts" runat="server" NavigateUrl="">HyperLink</asp:HyperLink><br />

    <asp:HyperLink ID="NewProducts" runat="server" NavigateUrl="">HyperLink</asp:HyperLink><br />

    </asp:Content>

  • Re: Linking a page to two Master Pages?

    05-09-2008, 3:22 PM
    Answer
    • Loading...
    • linjitvd
    • Joined on 04-02-2008, 10:57 AM
    • Posts 14

    Too many ways to do it. If you have design the menu for each role, try my code

    If Roles.IsUserInRole("Administrator") Then
       mainmenuAdmin.visible=true
       mainmenuMember.visible=false
    
    elseif Roles.IsUserInRole("Member")  Then
       mainmenuAdmin.visible=false
       mainmenuMember.visible=true
    else
    
    endif
    
    <div id="mainmenuAdmin" runat="server"><ul> <li><a href="../AddRecords.aspx">Add Quotes</a></li> <li><a href="ViewQuote.aspx">View Quote</a></li><li><a href="Upload.aspx">Upload New Products</a></li><li><a href="../NewProducts.aspx">New Products</a></li></ul></div>
    <div id="mainmenuMember" runat="server" visible="false"><ul> <li><a href="AddRecords.aspx">Add Quotes</a></li><li><a href="NewProducts.aspx">New Products</a></li></ul></div>
    
     
Page 1 of 1 (6 items)