change <body> tag from Page_Load event?

  • Thread starter Thread starter SteveS
  • Start date Start date
S

SteveS

Hello, I'm having trouble figuring out how to dynamically add an onload and
resize event to the <body> tag. I've looked on the web and in MS
documentation unsuccessfuly. Does anyone know the code to do this? The end
result would be something like this:

<body onload="MyFunction()" resize="ResizeFunction()">

Your help is greately appreciated!!!
 
Yes, here is one possible solution:

Give your body tag the runat and id attributes:

<body runat="server" id="Body">

Then from code behind, obtain a reference to the control and make it
sumbit to your wishes:

HtmlGenericControl body = FindControl("Body") as HtmlGenericControl;
if (body != null)
{
body.Attributes["onload"] = "MyFunction();";
}

HTH,
 
try adding a runat=server and declaring it in the codebehind, then you can
do what you want with it
 
If you make protected properties onLoadHandler and onResizeHandler that will
hold the text you want to use in onload and resize, you can simply write

<body onload="<%=onLoadHandler %>" resize="<%=onResizeHandler %>">

Eliyahu
 
Curt_C said:
try adding a runat=server and declaring it in the codebehind, then you can
do what you want with it

Heh, it would be cool if ASP.NET allows events fired on client-side to
post back directly, something like:
 
Back
Top