473,383 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Access to body ID of Master Page

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
Mar 4 '08 #1
3 2327
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.At tribute.Add("onload","GetAccounts()");

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

"tshad" <ts***@dslextreme.comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
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

Mar 4 '08 #2

"Mark Fitzpatrick" <ma******@fitzme.comwrote in message
news:OK**************@TK2MSFTNGP04.phx.gbl...
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.At tribute.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" <ts***@dslextreme.comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
>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


Mar 4 '08 #3
"tshad" <ts***@dslextreme.comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
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

Mar 4 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tony | last post by:
Hi, I'm trying to access properties from a masterpage. With no success. Can somebody help me please? I used the example at:...
0
by: gregtyndall | last post by:
I have a weird problem. I'm using a master page to hold a menu that I want to scroll as the user scrolls in the browser window so it will always be visible. First off, putting onsroll in the body...
3
by: ivanpais | last post by:
Hi, I have a Web User Control, Lets say "Foo.ascx", that contains a button "btnFoo". I have a Master Page "Bar.master", that has a label "lblBar". This label is exposed by a public property...
1
by: PCK | last post by:
My goal is to populate the body element so that I can add an onkeydown event. <body onkeydown='x();'></body> I am currently using master/content pages. I do not want this function on every...
0
by: bluegrasslover | last post by:
I've gotten a couple of emails about this problem lately so I'm going to post the solution that someone emailed me a while back. When you create a master page visual studio automatically adds a...
4
by: Jason | last post by:
Hi, Here's the scenario: I have a web application that has window A and window B. A user has both window A and B open - window A is in the foreground and window B is behind it. If the...
5
by: mazdotnet | last post by:
Hi, I have a master file with the following setting <body runat="server" id="Body"> and in the .cs I have Body.Attributes.Add("onload", "menuCurrentPage('current','navlist');"); Now in one...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
2
by: tshad | last post by:
I have the body tag of my page in my master page. <body id="MyBody" runat="server"> In my control that is on the page, I want to set the onload event which I would do if it was in my control...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.