How to get reference of the <body runat=server id=.../> on server side?

  • Thread starter Thread starter feng
  • Start date Start date
F

feng

I need to add an "onload" attribute to <body> tag so that
I can insert client side JavaScript when the page is
reloaded. It looks like I should be able to get a
reference to the <body> control as it takes
a "runat=server" attribute. But I still don't know how to
define this body control in code behind. Can someone show
me how to do this?

Thanks
 
1) Give the body tag a unique ID.
2) In the code-behind, declare an instance variable that can map to the tag
(protected HtmlGenericControl myBodyTag;) where the name of this variable is
the same as the tag ID.

Now you should be able to manipulate the <body> tag by using the methods and
properties on the variable.
 
Back
Top