setting the Master page of an existing form

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
 
G

Guest

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
 
G

Guest

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
 
M

Mark Rae [MVP]

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...?
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top