473,951 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Attribut e.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 2352
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.M asterPage).MyBo dy.Attribute.Ad d("onload","Get Accounts()");

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

"tshad" <ts***@dslextre me.comwrote in message
news:%2******** *******@TK2MSFT NGP04.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.Attribut e.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******@fitzm e.comwrote in message
news:OK******** ******@TK2MSFTN GP04.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.M asterPage).MyBo dy.Attribute.Ad d("onload","Get Accounts()");
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***@dslextre me.comwrote in message
news:%2******** *******@TK2MSFT NGP04.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.Attribu te.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***@dslextre me.comwrote in message
news:%2******** *******@TK2MSFT NGP04.phx.gbl.. .
How can I put attributes on the body tag from a child page or control?
Master.FindCont rol("MyBody").A ttribute.Add("o nload","GetAcco unts()");
--
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
1111
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: http://msdn.microsoft.com/library/en-us/dnvs05/html/masterpages.asp?frame=false#masterpages_topic11 (Exposing Properties and Methods from a Master Page) here my code:
0
2748
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 tag of my master page does nothing. Oh, IE is the browser. <body onscroll="alert('scrolling')"> I was able to get around this setting an event hander for window.onscroll. However, body.scrollTop is always 0! I wrote a plain aspx test...
3
6462
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 BarLabelText. I now have a contentpage "FooBar.aspx", where "Bar.master" is the master page and in the content section has the control "Foo.ascx".
1
1972
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 page using my master page. I want to be able to decide what pages get this function on a page by page basis. Because of this I cannot just add the text to the html side of the master page as it would cause unwanted results on the pages where I do...
0
2676
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 <-- doctype ... statement near the top of the master page. Somehow this forces some w3c standard where scrolltop isn't supported. I removed the doctype declaration from my masterpage and everything works fine. Actually I changed the dtd type to...
4
4073
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 user looking at window A clicks the "open window B" link, I want
5
8402
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 of my content files I want to add an additional parameter to the onload
6
9181
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" %> On the Master Page I have a public property exposed: Public Property ErrorMessage() As String Get Return txtError.InnerText End Get
2
1539
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 but it isn't: MyBody.Attributes.Add("onclick", "TestIt();"); Is there a way to do this from the control?
0
9998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10704
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9913
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8277
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6237
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6360
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.