That is right, on my page's OnPreRender method I tried to do those things
without success.
I managed to derive the right control name given by ASP.NET using the
following:
private string DeriveClientID(string programmaticId, HtmlHead head)
{
string ctlPrefix = head.ClientID.Replace(head.ID, "");
return string.Format("{0}{1}", ctlPrefix, programmaticId);
}
so if my HEAD server element (accessed in ASP.NET 2.0 with the Header
property of the page) has ID="Head1" and ClientID="ctl00_Head1" then that
means that if I set BODY id="Body" using this method would return me
"ctl00_Body" as the client ID which in theory I could have used to find the
right control.
The problem is.... even when you use FindControl on the page with the
correct ID string (ctl00_Body) that appears rendered on the page, it would
still not find the control.
Control body = FindControl(DeriveClientID("Body", Header));
would still return body == null even when the ID is the correct one. As it
appears the HEADER is ultra special because if you use the id and runat on
the BODY tag it would still not be accessible by the page.
For curiosity I put the BODY tag within the hierarchy of the FORM tag on the
asp.net page but the results where the same, it still cannot find the
control.
Also tried as someone suggested, by registering a client script block that
would set the window.onload and window.onunload to set the functions to be
called but that does not work either.
Any other ideas?
"Riki" <ri**@dontnagme.comwrote in message
news:Ob**************@TK2MSFTNGP05.phx.gbl...
So you're trying to access it from within the page, not from within the
master page?
Try this (I'm using VB.NET):
CType(Page.Master,MyMasterClassName).Body.ClientID
Replace MyMasterClassName with the real class name of your master page.
Don't use quotes.
However, it's a bad idea to try to access the master from within the page.
It's against OOP principles (code in the page should not depend on code in
the master).
Maybe you can achieve what you want with the
RegisterClientStartupScript method?
--
Riki
"~~~ .NET Ed ~~~" <ti*********@abolishspam.nowwrote in message
news:OT**************@TK2MSFTNGP06.phx.gbl...
>Remember that my body ID is "Body" and that ASP.NET converts it to
something like "ctl100_Body" which may change. I tried using
FindControl("Body") but returns null so I can't find the server control
and since I don't have that I don't have any object to use the ClientID
property on.
"Riki" <ri**@dontnagme.comwrote in message
news:ee**************@TK2MSFTNGP06.phx.gbl...
>>>
In that case, use YourBodyID.ClientID instead of YourBodyID.
--
Riki