setting the Master page of an existing form

Discussion in 'ASP .Net' started by =?Utf-8?B?QW50?=, Nov 5, 2007.

  1. Hi,

    If I have created a web form, then create the Master Page, how can I set a
    reference to that Master page from my web form?

    Many thanks for any answers

    Ant
    =?Utf-8?B?QW50?=, Nov 5, 2007
    #1
    1. Advertising

  2. "Ant" <> wrote in message
    news:D...

    > If I have created a web form, then create the Master Page, how can I set a
    > reference to that Master page from my web form?


    this.Master.......


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Nov 5, 2007
    #2
    1. Advertising

  3. Thanks Mark,

    I added this to my Page Load event:


    this.Master = "MasterPage.master";

    but got a compile error saying that the property was read only.

    Could you perhaps give me a bit more information regarding this & also, is
    it possible to do this via the properties box?

    Many thanks for your help with this

    Cheers

    Ant




    "Mark Rae [MVP]" wrote:

    > "Ant" <> wrote in message
    > news:D...
    >
    > > If I have created a web form, then create the Master Page, how can I set a
    > > reference to that Master page from my web form?

    >
    > this.Master.......
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
    =?Utf-8?B?QW50?=, Nov 6, 2007
    #3
  4. Howdy,

    Two ways:

    1. Declaratively in aspx page:
    <%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master"
    AutoEventWireup="true" CodeFile="Whatever.aspx.cs" Inherits="Whatever"
    Title="Whatever" %>

    2. Programatically, in the PreInit event:

    protected void Page_PreInit(object sender, EventArgs e)
    {
    this.MasterPageFile = "~/MasterPages/MasterPage.master";
    }


    Hope this helps
    --
    Milosz


    "Ant" wrote:

    > Thanks Mark,
    >
    > I added this to my Page Load event:
    >
    >
    > this.Master = "MasterPage.master";
    >
    > but got a compile error saying that the property was read only.
    >
    > Could you perhaps give me a bit more information regarding this & also, is
    > it possible to do this via the properties box?
    >
    > Many thanks for your help with this
    >
    > Cheers
    >
    > Ant
    >
    >
    >
    >
    > "Mark Rae [MVP]" wrote:
    >
    > > "Ant" <> wrote in message
    > > news:D...
    > >
    > > > If I have created a web form, then create the Master Page, how can I set a
    > > > reference to that Master page from my web form?

    > >
    > > this.Master.......
    > >
    > >
    > > --
    > > Mark Rae
    > > ASP.NET MVP
    > > http://www.markrae.net
    > >
    > >
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Nov 6, 2007
    #4
  5. "Ant" <> wrote in message
    news:...

    > Could you perhaps give me a bit more information regarding this & also, is
    > it possible to do this via the properties box?


    What are you actually trying to do?

    Your OP said you want to "set a reference" to the MasterPage from the
    content page...

    E.g. to refer to a control on the MasterPage, you'd use something like:

    MasterPageTextBox TextBox = (TextBox)this.Master.FindControl("MyTextBox");

    Is that not what you meant...?


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Nov 6, 2007
    #5
  6. Apologies for the misunderstanding,

    When I said reference, I meant how to 'associate' a web form with a
    particular master page. I believe the above poster answered the question.

    Many thanks though

    Ant

    "Mark Rae [MVP]" wrote:

    > "Ant" <> wrote in message
    > news:...
    >
    > > Could you perhaps give me a bit more information regarding this & also, is
    > > it possible to do this via the properties box?

    >
    > What are you actually trying to do?
    >
    > Your OP said you want to "set a reference" to the MasterPage from the
    > content page...
    >
    > E.g. to refer to a control on the MasterPage, you'd use something like:
    >
    > MasterPageTextBox TextBox = (TextBox)this.Master.FindControl("MyTextBox");
    >
    > Is that not what you meant...?
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
    =?Utf-8?B?QW50?=, Nov 6, 2007
    #6
    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,002
    William Brogden
    Aug 5, 2004
  2. Laith Zraikat
    Replies:
    3
    Views:
    1,213
    Walter Wang [MSFT]
    Jul 6, 2006
  3. Zeba
    Replies:
    1
    Views:
    487
    Mark Rae
    Feb 22, 2007
  4. Nathan Sokalski
    Replies:
    25
    Views:
    1,426
    Nathan Sokalski
    Mar 4, 2010
  5. SerpentKiss2010
    Replies:
    0
    Views:
    2,483
    SerpentKiss2010
    Apr 6, 2011
Loading...

Share This Page