Accessing Master Page Custom Properties in Design Mode

Discussion in 'ASP .Net' started by =?Utf-8?B?U3VyZXNo?=, Oct 21, 2006.

  1. Is there any way to access the custom properties of a master page from the
    aspx form?

    I know the custom properties of a master page can be accessed from the
    aspx.cs partial class by specifying the MasterType directive on the aspx form.

    My master page will render a custom navigation menu and I'd like to put in
    the properties of which tab and sub tab to load and other misc style info in
    the aspx form that can be used by master page.

    Thanks in advance,
    Suresh.
     
    =?Utf-8?B?U3VyZXNo?=, Oct 21, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?U3VyZXNo?=

    Siva M Guest

    Cast the return value of Page.Master to your specific master page type and
    set/get its properties.

    "Suresh" <> wrote in message
    news:...
    Is there any way to access the custom properties of a master page from the
    aspx form?

    I know the custom properties of a master page can be accessed from the
    aspx.cs partial class by specifying the MasterType directive on the aspx
    form.

    My master page will render a custom navigation menu and I'd like to put in
    the properties of which tab and sub tab to load and other misc style info in
    the aspx form that can be used by master page.

    Thanks in advance,
    Suresh.
     
    Siva M, Oct 21, 2006
    #2
    1. Advertising

  3. Isn't what you are saying only possible from the codebehind??

    "Siva M" wrote:

    > Cast the return value of Page.Master to your specific master page type and
    > set/get its properties.
    >
    > "Suresh" <> wrote in message
    > news:...
    > Is there any way to access the custom properties of a master page from the
    > aspx form?
    >
    > I know the custom properties of a master page can be accessed from the
    > aspx.cs partial class by specifying the MasterType directive on the aspx
    > form.
    >
    > My master page will render a custom navigation menu and I'd like to put in
    > the properties of which tab and sub tab to load and other misc style info in
    > the aspx form that can be used by master page.
    >
    > Thanks in advance,
    > Suresh.
    >
    >
     
    =?Utf-8?B?U3VyZXNo?=, Oct 21, 2006
    #3
  4. =?Utf-8?B?U3VyZXNo?=

    Siva M Guest

    Yes.

    "Suresh" <> wrote in message
    news:...
    Isn't what you are saying only possible from the codebehind??

    "Siva M" wrote:

    > Cast the return value of Page.Master to your specific master page type and
    > set/get its properties.
    >
    > "Suresh" <> wrote in message
    > news:...
    > Is there any way to access the custom properties of a master page from the
    > aspx form?
    >
    > I know the custom properties of a master page can be accessed from the
    > aspx.cs partial class by specifying the MasterType directive on the aspx
    > form.
    >
    > My master page will render a custom navigation menu and I'd like to put in
    > the properties of which tab and sub tab to load and other misc style info
    > in
    > the aspx form that can be used by master page.
    >
    > Thanks in advance,
    > Suresh.
    >
    >
     
    Siva M, Oct 21, 2006
    #4
  5. Figured it out!! (Using a different approach)

    First of all there doesn't seem to be a way to specify the custom properties
    of a master page in the aspx form.

    But I can add custom attributes to the Page directive by using a base page
    class that my web forms can inherit. I can put my custom properties in my
    base page and set them on the aspx form in design mode. This is only
    possible if I set the CodeFileBaseClass of Page in the aspx form to my base
    page class.

    Then from my master page I'm able to interrogate this properties.

    However, I'm not sure if this is the best solution.

    Example below:

    1. BasePage

    public class BasePage : System.Web.UI.Page
    {
    private string _Header;

    public string Header
    {
    get { return _Header; }
    set { _Header = value; }
    }

    public BasePage() { }
    }

    2. Page directive on my aspx form (Note: Header and CodeFileBaseClass
    settings)

    <%@ Page Language="C#" MasterPageFile="~/App_Master/Main.master"
    CodeFileBaseClass="BasePage" Header="This is a Test!" AutoEventWireup="true"
    CodeFile="SamplePage.aspx.cs" Inherits="App_Pages_SamplePage" Title="Sample
    Page" %>

    3. Master Page

    public partial class App_Master_Main : System.Web.UI.MasterPage
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (Page is BasePage)
    {
    BasePage p = (BasePage)this.Page;
    ltlFormHeader.Text = p.Header;
    }
    }
    }

    If anyone is interested in this and can actually follow what I'm doing and
    realize that this is bad... Please let me know a better way.

    Thanks,
    Suresh.

    "Suresh" wrote:

    > Is there any way to access the custom properties of a master page from the
    > aspx form?
    >
    > I know the custom properties of a master page can be accessed from the
    > aspx.cs partial class by specifying the MasterType directive on the aspx form.
    >
    > My master page will render a custom navigation menu and I'd like to put in
    > the properties of which tab and sub tab to load and other misc style info in
    > the aspx form that can be used by master page.
    >
    > Thanks in advance,
    > Suresh.
     
    =?Utf-8?B?U3VyZXNo?=, Oct 21, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug McCann
    Replies:
    1
    Views:
    1,099
    William Brogden
    Aug 5, 2004
  2. John J Lee
    Replies:
    3
    Views:
    519
    bruno at modulix
    Dec 1, 2005
  3. William Youngman
    Replies:
    3
    Views:
    703
    William Youngman
    Apr 2, 2007
  4. evantay
    Replies:
    4
    Views:
    774
    Walter Wang [MSFT]
    May 30, 2007
  5. Edward Loper
    Replies:
    0
    Views:
    504
    Edward Loper
    Aug 7, 2007
Loading...

Share This Page