Access to body ID of Master Page

  • Thread starter Thread starter tshad
  • Start date Start date
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
 
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
 
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
 
Back
Top