How to access ID in Master Page

T

tshad

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
 
P

Peter Bromberg [C# MVP]

Have you tried Page.FindControl("MyBody")? Or, Master.FindControl (whichever
the case may require)?
Peter
 
M

Madhur

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,538
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top