473,951 Members | 11,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to access ID in Master Page

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.Attribut es.Add("onclick ", "TestIt();" );

Is there a way to do this from the control?

Doing this gives me the error:

Error 5 The name 'MyBody' does not exist in the current context

Thanks,

Tom
Jun 27 '08 #1
2 1538
Have you tried Page.FindContro l("MyBody")? Or, Master.FindCont rol (whichever
the case may require)?
Peter

"tshad" <ts***@dslextre me.comwrote in message
news:u1******** ******@TK2MSFTN GP06.phx.gbl...
>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.Attribut es.Add("onclick ", "TestIt();" );

Is there a way to do this from the control?

Doing this gives me the error:

Error 5 The name 'MyBody' does not exist in the current context

Thanks,

Tom

Jun 27 '08 #2
In the content page, include an @MasterType directive. This will cause the
..Master property to be automatically cast to the correct type so that you
can access any of it's methods and/or properties.
--
MAdhur

"tshad" <ts***@dslextre me.comwrote in message
news:u1******** ******@TK2MSFTN GP06.phx.gbl...
>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.Attribut es.Add("onclick ", "TestIt();" );

Is there a way to do this from the control?

Doing this gives me the error:

Error 5 The name 'MyBody' does not exist in the current context

Thanks,

Tom

Jun 27 '08 #3

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

Similar topics

2
4190
by: Steve Franks | last post by:
I am trying to access strongly typed properties in a page's master page from the content page. I followed an article that describes how to do this, and it seems quite straight forward. However when I try to access the property from my content page intellisense does not show the public property. Likewise when I go to compile I get an error saying that Specifically here is the article I am trying to follow: ...
5
7293
by: RedHair | last post by:
I have a ASP.NET 2.0 web page which inherits a customized base page class and have a master page, their relation is as below Customized base page class --> web page --> master page How to access the property and control of master page from the customized base page class? Btw, I can access the server control of master page from base page class via
4
6031
by: RedHair | last post by:
I have a base page class A which inherits System.Web.UI.Page class then a aspx page B inherits class A and have a master page C. There is a property D (a string variable) in the master page C. How can I access the property D from the base page class A? PS: I know how to use reflection to access control of master page C from the base class A.
5
1968
by: Paul | last post by:
I have a MasterPage that has on it several UserControls (*ascx files). I wish to control the visibility of the controls on the content pages according to some parameter (for example on a user control that depends on a param StoreID, for the UserControl to be visible only if StoreID is in the query string.) How can I access a UserControl in a MasterPage from a Content page? I tried this, and variations thereof, but get errors: ...
3
2102
by: Alex Maghen | last post by:
Hi. I'm a little confused about the code that resides in the code-behind of a MasterPage and the code that resides in the code-behind of the actual pages that USE that MasterPage. I'm noticing, for example, that the Page_Load on the specific page executes before the Page_Load of its MasterPage. Is this right? But what I really want to understand is VARIABLE SCOPE, etc. between the two. For example: Is there a way for me to write code...
4
1648
by: Bob | last post by:
In ASP.NET 1.1, I have a base page for all my pages in an application. The base page contains some common properties that every page needs, the code behind file of every page looks like this: public class Home : MyBasePage { ..... } and in it I can simply refer them as base.MyProperty (or just this.MyProperty). This seems no longer possible in the ASP.NET 20 master
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".
4
4009
by: Boris Yeltsin | last post by:
OK, on my Master Page I have a control: <a id="hypTabAccount" href="#" runat="server">Account</a> Now, in the code-behind (Root.master.vb) I can refer to it simply thus: hypTabAccount.InnerText = "blah" Now, what I want is the same in a content page that uses the Master Page. I have a Master Type in my Content page:
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
3
1284
by: eselk2003 | last post by:
I'm just starting out with VWD 2008, and new to ASP .NET. I have a master page which displays one record for an Access database based on an ID number in the query string. Then I have a content page that displays some other records which are also filtered by that ID. I'd like to do just one query in the master page, which returns all fields for that main record, then just use those fields in the details page instead of doing a seperate...
1
11374
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
10703
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
9905
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
8269
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
7444
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6235
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
6353
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3560
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.