setting the Master page of an existing form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
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...?
 
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
 
Back
Top