Master Pages

Last post 05-17-2005 4:39 PM by mohan_nz. 9 replies.

Sort Posts:

  • Master Pages

    05-13-2005, 1:28 PM
    • Member
      30 point Member
    • mohan_nz
    • Member since 10-29-2002, 5:27 PM
    • Posts 6

    I have a MasterPage which has couple of buttons and some Security Methods
    which is common on all pages, Say on Page load u check for it, Lets call it
    ValidateUser(). Since its used in all pages i create it in Master Page.

    Now I have another Master Page, Lets say we Have Authentication Folder and
    we have a master Page which has headers related to Authentication, and this
    one has a Method CreateHeader() and this AuthmasterPage derives from Root
    Master Page.

    I create a Content Page inside Authentication Folder which has
    Auth.MasterPage as its master Page. Now i am trying to access the
    CreateHeader() or ValidateUser() method inside this page, it cannot find it.
    But the AuthMaster page can See the ValidateUser() method from Root Master
    Page.

    Does anyone have a solution or Help in regard to this.



     

  • Re: Master Pages

    05-14-2005, 2:25 AM
    • Participant
      805 point Participant
    • richy_roo
    • Member since 12-18-2004, 1:24 PM
    • Posts 161
    i've never tried this, sound like it should work,if it dont the option would be to wrap create a public method in your autmasterpage called AuthValidateUser which just calls the validate user
  • Re: Master Pages

    05-14-2005, 2:27 AM
    • Participant
      805 point Participant
    • richy_roo
    • Member since 12-18-2004, 1:24 PM
    • Posts 161

    also check out this post, make sure you've not missed anything in the page using authmaster

    http://forums.asp.net/924072/ShowPost.aspx

  • Re: Master Pages

    05-14-2005, 1:16 PM
    • Member
      30 point Member
    • mohan_nz
    • Member since 10-29-2002, 5:27 PM
    • Posts 6

    I understood of what your were trying to say, but the problem is i have to repeat the Methods in each and every page and i have some were around 600+ pages.

    In Frmwrk 1.1 i used a Base Abstract class with has these and some more methods and the class extends from System.Web.Ui. The webfarm will inherit from this base and it was easy to work with. I am trying to achive the same with Master page, if this works it will reduce lots of development and Maintance issues. The only issue with the previous implementation is you will not be able to view the page in design mode cause it does not inherit directly from System.Web.UI.

    Anyway thanks for the info, if you get any other result let me know.
    I will try keep this forum if there was any progress.

    Cheers


  • Re: Master Pages

    05-17-2005, 1:10 AM
    • Contributor
      2,738 point Contributor
    • kashif
    • Member since 06-11-2002, 1:34 PM
    • Posts 547
    • AspNetTeam
      Moderator

    Mohan, can't you define the ValidateUser method in your base class and have both the normal master and the auth master inherit from this class so that the method is available to both masters?

    Hope that helps, Kashif

  • Re: Master Pages

    05-17-2005, 10:44 AM
    • Member
      30 point Member
    • mohan_nz
    • Member since 10-29-2002, 5:27 PM
    • Posts 6

    I assume that i had tried this, but had some problem, I am not sure what it was, Let me try again and let update you.

  • Re: Master Pages

    05-17-2005, 2:07 PM
    • Member
      30 point Member
    • mohan_nz
    • Member since 10-29-2002, 5:27 PM
    • Posts 6
    Kashif, As i said, i did try that, but the Content Page cannot see the Extended Methods in Sub or Root Master Page. I jst tried it again and the result was same.
  • Re: Master Pages

    05-17-2005, 2:33 PM
    • Contributor
      2,738 point Contributor
    • kashif
    • Member since 06-11-2002, 1:34 PM
    • Posts 547
    • AspNetTeam
      Moderator

    Can you provide the code you are using? Can you ensure that you define the MasterType directive on page ot enable strong typed access to the masterpage's methods and prop.

    Thanks!

  • Re: Master Pages

    05-17-2005, 4:22 PM
    • Participant
      1,431 point Participant
    • rstrahl
    • Member since 08-20-2003, 1:08 PM
    • Paia, Hawaii
    • Posts 277
    • ASPInsiders
      TrustedFriends-MVPs

    Mohan,

    I think your issue is the new compilation model in 2.0. ASPX pages and their partial code behinds are no longer visible because they get dynamically generated at compile time.

    However, the 1.1 model still works. I think what you'll want to do is create a Base page that uses either just code or code and controls, but make sure to set it up as an 1.1 style codebehind class in your App_Code folder, rather than a partial class that ASP.NET creates dynamically.

    Once you do that you can easily inherit from it.

    You might find this discussion interesting as I fought this very issue just a few days ago:
    http://west-wind.com/weblog/posts/2128.aspx

    +++ Rick ---

    Rick Strahl
    West Wind Technologies
    Making waves on the Web
    www.west-wind.com/weblog
  • Re: Master Pages

    05-17-2005, 4:39 PM
    • Member
      30 point Member
    • mohan_nz
    • Member since 10-29-2002, 5:27 PM
    • Posts 6

    Base Class which will have the common Functions, I have jst defined only a click event and a GetStr Method.

    public class ProductBase : System.Web.UI.MasterPage
    {
       public string GetStr()
       {
          return "hello";
       }

       protected virtual void Button1_Click(object sender, EventArgs e)
       {
          Response.Write(
    "<BR>Master Btn Clicked<BR>");
       }

    }

    The Master Page in the root will have a Button and i have the Click event for it define in the ProductBase.

    public partial class MasterPage : ProductBase
    {
       
    protected void Page_Load(object sender, EventArgs e)
       {
          Response.Write(
    "<BR> From Master Page <BR>");
       
    }

       public string GetVal()
       {
          
    return "Hello from root Master";
       }
    }

    AuthMasterPage
    <%@ Master MasterPageFile="~/MasterPage.master" Language="C#" AutoEventWireup="true" CodeFile="AuthMasterPage.master.cs" Inherits="AuthMasterPage" %>
    <asp:content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
       <asp:TextBox ID="TextBox11" runat="server"></asp:TextBox>
    </asp:content>

    public partial class AuthMasterPage : ProductBase
    {
       
    public MasterPage rootMaster;
       
    protected void Page_Load(object sender, EventArgs e)
       {
          rootMaster = (
    MasterPage)this.Master;
          rootMaster.GetVal();
       }
       
       public string GetAuthVal()
       {
          
    return rootMaster.GetVal();// "Hello From Auth";
       
    }
    }

    Content Page in Auth folder....
    <%@ Page Language="C#" MasterPageFile="~/Authentication/AuthMasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>

    public partial class _Default : System.Web.UI.Page
    {
       
    protected void Page_Load(object sender, EventArgs e)
       {
          
    MasterPage mp = (MasterPage)this.Master;
          
    //mp.ge
        
    }
    }

    Let me know if anything in not clear or i have missed.

    Thanks
    Mohan

Page 1 of 1 (10 items)