473,396 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

change <body> tag from Page_Load event?

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!!!

Nov 19 '05 #1
5 1588
try adding a runat=server and declaring it in the codebehind, then you can
do what you want with it

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"SteveS" <sm*******@yahoo.com> wrote in message
news:u2**************@TK2MSFTNGP09.phx.gbl...
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!!!

Nov 19 '05 #2
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,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 13 Feb 2005 00:34:35 -0500, "SteveS" <sm*******@yahoo.com>
wrote:
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!!!


Nov 19 '05 #3
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

"SteveS" <sm*******@yahoo.com> wrote in message
news:u2**************@TK2MSFTNGP09.phx.gbl...
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!!!

Nov 19 '05 #4
Curt_C [MVP] wrote:
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:
<body runat="server" onload="MyPage.MyFunction">

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"SteveS" <sm*******@yahoo.com> wrote in message
news:u2**************@TK2MSFTNGP09.phx.gbl...
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!!!


Nov 19 '05 #5
controls can do an autopostback but when its not an ASP control you are
limited

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Curt_C [MVP] wrote:
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:
<body runat="server" onload="MyPage.MyFunction">

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"SteveS" <sm*******@yahoo.com> wrote in message
news:u2**************@TK2MSFTNGP09.phx.gbl...
> 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!!!
>
>
>

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ryan.mclean | last post by:
Hello everyone. Hope ya'll had a nice New Year. Anyway, my question is why won't this work? I must be doing something dumb . . . here is the code: in the body tag, I have this code (just to...
3
by: francescomoi | last post by:
Hi. I'm trying to insert some text between <head> and <body> but I'm not able. I try with: -------- bodyPoint = document.getElementsByTagName('body'); var myLink =...
15
by: Frances | last post by:
<html> <head> <script> function doIt() { var list = document.forms.product; var selItem = list.options.value; ^^^^^^^ </head>
3
by: =B= | last post by:
Hi all, I was wondering if anyone has had any luck with trapping the <BODY> onUnload() event in ASP.NET? The thing is, I'm writing code for an Intranet site. The code makes a call to a...
0
by: WB | last post by:
Hi, How can I add an "onbeforeunload" event to the body tag of the MasterPage? All pages in my site follow a MasterPage and some of these pages require long processing. I'd like to show a...
12
by: Mark Rae | last post by:
Hi, It's easy enough for a child page to manipulate its MasterPage's header simply by modifying the MasterPage thus: <header runat="server"> .... .... </header>
3
by: =?Utf-8?B?RGVkZ2U=?= | last post by:
Unlike 2003, VS 2005 issues errors when the <bodytag includes the scroll= attribute and when asp:Panel or <divtags specify the onscroll event. What is the preferred 2005 technique to implement...
23
by: Xah | last post by:
Here's a interesting case of invalid html 4 strict file. In summary, if you have <body></bodywithout any content, the file would be invalid under html 4 strict. Valid if html 4 lose. <!DOCTYPE...
3
by: PYG | last post by:
Hi everybody I have a simple question : If i use this code : <body style="font-size:24px;color:blue;"> Text in body <table> <tr><td> Text in table
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.