Access to body ID of Master Page

T

tshad

In VS 2005,

I need to get access to the body tag which I have set up on my Master Page
as:

<body ID="MyBody" runat="server">

But when do something like:

MyBody.Attribute.Add("onload","GetAccounts()");

But I get:

Error 1 The name 'MyBody' does not exist in the current context

I also tried Page.MyBody, but that doesn't work either.

How can I put attributes on the body tag from a child page or control?

Thanks,

Tom
 
M

Mark Fitzpatrick

You need to access the MasterPage property of your page or control, then
cast it to the type of your MasterPage. The MasterPage property is cast to
the MasterPage base type so it won't have any of the properties or controls
you may create within the master page, unless you cast it to the specific
master page type, like
((mysite.pages.mymaster)this.MasterPage).MyBody.Attribute.Add("onload","GetAccounts()");

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression
 
T

tshad

Mark Fitzpatrick said:
You need to access the MasterPage property of your page or control, then
cast it to the type of your MasterPage. The MasterPage property is cast to
the MasterPage base type so it won't have any of the properties or
controls you may create within the master page, unless you cast it to the
specific master page type, like
((mysite.pages.mymaster)this.MasterPage).MyBody.Attribute.Add("onload","GetAccounts()");

Not sure what you mean here.

Is "mysite" my namespace? I tried that but got an error. I also can't find
an entry that will allow my to put pages in. Also what is mymaster?

Thanks,

Tom
 

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

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top