PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

Access to body ID of Master Page

 
 
tshad
Guest
Posts: n/a
 
      4th Mar 2008
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


 
Reply With Quote
 
 
 
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      4th Mar 2008
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



"tshad" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>
>


 
Reply With Quote
 
tshad
Guest
Posts: n/a
 
      4th Mar 2008

"Mark Fitzpatrick" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
> Hope this helps,
> Mark Fitzpatrick
> Microsoft MVP - Expression
>
>
>
> "tshad" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> 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
>>
>>

>



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      4th Mar 2008
"tshad" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...

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


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


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Control inside content page to access Master Page Vars Poofactory Microsoft ASP .NET 2 19th Apr 2008 07:46 AM
How can I access a Master Page Public Property from a Base Page =?Utf-8?B?SmF5IFBvbmR5?= Microsoft ASP .NET 6 14th Nov 2007 12:06 PM
Access a Master Page Property from content page CodeBehind Matt Microsoft VB .NET 0 29th Nov 2006 03:41 PM
Access property and control of master page from a customized parent page class RedHair Microsoft ASP .NET 5 23rd Mar 2006 01:39 PM
access content page controls from within the master page phil1bruening@web.de Microsoft ASP .NET 4 23rd Nov 2005 08:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:09 PM.