Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to access ID in Master Page

Reply
Thread Tools

How to access ID in Master Page

 
 
tshad
Guest
Posts: n/a
 
      05-15-2008
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?

Doing this gives me the error:

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

Thanks,

Tom


 
Reply With Quote
 
 
 
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      05-15-2008
Have you tried Page.FindControl("MyBody")? Or, Master.FindControl (whichever
the case may require)?
Peter

"tshad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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?
>
> Doing this gives me the error:
>
> Error 5 The name 'MyBody' does not exist in the current context
>
> Thanks,
>
> Tom
>
>


 
Reply With Quote
 
 
 
 
Madhur
Guest
Posts: n/a
 
      05-16-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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?
>
> Doing this gives me the error:
>
> Error 5 The name 'MyBody' does not exist in the current context
>
> Thanks,
>
> Tom
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to Access Master Page Controls from page.aspx doesn't inherit from master SerpentKiss2010 ASP .Net 0 04-06-2011 02:46 PM
Setting the value of a Master page's control's property using a property of the Master page Nathan Sokalski ASP .Net 25 03-04-2010 03:42 AM
Can a master page be built from another master page Zeba ASP .Net 1 02-22-2007 10:55 AM
seeking servlet "Master" keep getting "Master/servlet/Master" not found. Tomcat 5.0.25 Doug McCann Java 1 08-05-2004 09:16 PM



Advertisments