Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Access to body ID of Master Page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tshad - 04 Mar 2008 18:25 GMT
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
Mark Fitzpatrick - 04 Mar 2008 18:37 GMT
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

> In VS 2005,
>
[quoted text clipped - 18 lines]
>
> Tom
tshad - 04 Mar 2008 18:48 GMT
> 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
[quoted text clipped - 22 lines]
>>
>> Tom
Mark Rae [MVP] - 04 Mar 2008 19:14 GMT
> How can I put attributes on the body tag from a child page or control?

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

Signature

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


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.