473,659 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="MyFunct ion()" resize="ResizeF unction()">

Your help is greately appreciated!!!

Nov 19 '05 #1
5 1607
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*******@yaho o.com> wrote in message
news:u2******** ******@TK2MSFTN GP09.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="MyFunct ion()" resize="ResizeF unction()">

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:

HtmlGenericCont rol body = FindControl("Bo dy") as HtmlGenericCont rol;
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*******@yaho o.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
documentatio n unsuccessfuly. Does anyone know the code to do this? The end
result would be something like this:

<body onload="MyFunct ion()" resize="ResizeF unction()">

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="<%=onLo adHandler %>" resize="<%=onRe sizeHandler %>">

Eliyahu

"SteveS" <sm*******@yaho o.com> wrote in message
news:u2******** ******@TK2MSFTN GP09.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="MyFunct ion()" resize="ResizeF unction()">

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*******@yaho o.com> wrote in message
news:u2******** ******@TK2MSFTN GP09.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="MyFunct ion()" resize="ResizeF unction()">

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*********@gm ail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.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*******@yaho o.com> wrote in message
news:u2******** ******@TK2MSFTN GP09.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="MyFunct ion()" resize="ResizeF unction()">
>
> 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
2036
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 test): <script LANGUAGE="javascript"> <!-- function hiThere() { alert("hi");
3
2294
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 = document.createElement("a");
15
2243
by: Frances | last post by:
<html> <head> <script> function doIt() { var list = document.forms.product; var selItem = list.options.value; ^^^^^^^ </head>
3
5870
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 third-party component (think of it as a lock) when the page loads. Now the OK and Cancel server buttons I can handle and use to release the lock as required. But previously in classic ASP I had been trapping the user hitting the close 'x' button by...
0
1493
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 "Processing. Please wait" message for these pages and need to add an "onbeforeunload" event to the body tag like so: <body onbeforeunload="ShowProcessingMessage();"> How can I accomplish this? Do I use the "Attributes.Add()" method?
12
4919
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
1466
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 this functionality? TIA
23
2227
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 HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/ TR/html4/strict.dtd"> <html> <head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=utf-8">
3
5743
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
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.