How to access ID in Master Page

  • Thread starter Thread starter tshad
  • Start date Start date
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
 
Have you tried Page.FindControl("MyBody")? Or, Master.FindControl (whichever
the case may require)?
Peter
 
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.
 
Back
Top