473,386 Members | 1,736 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,386 software developers and data experts.

Add body onload attribute from UserControl?

Hi all,

My application consists of a MasterPage which is used for all WebForms. I
then create UserControls to populate the content area for the different
WebForms.

In one complicated UserControl I have a number of Javscript functions.
Everything on the page works fine, until I try to add the OnLoad event
attribute to the Body tag which is generated by the Master Page.

I want to call a Javascript function upon Load of the page, but not for all
webforms, because only this particular control has the function declared.

How can I add the attribute from the code-behind of the User Control? I
can't add it in the declaration in the Master Page, because only one form
contains the code. Also, the JS Function references other document elements
that only reside in the particualr UserControl. Do I have a catch-22 here,
or can it be done?

Thanks to all...
Apr 3 '07 #1
5 3661
Try emitting the window.onload =functionname; convention instead. It works
the same.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"John Kotuby" wrote:
Hi all,

My application consists of a MasterPage which is used for all WebForms. I
then create UserControls to populate the content area for the different
WebForms.

In one complicated UserControl I have a number of Javscript functions.
Everything on the page works fine, until I try to add the OnLoad event
attribute to the Body tag which is generated by the Master Page.

I want to call a Javascript function upon Load of the page, but not for all
webforms, because only this particular control has the function declared.

How can I add the attribute from the code-behind of the User Control? I
can't add it in the declaration in the Master Page, because only one form
contains the code. Also, the JS Function references other document elements
that only reside in the particualr UserControl. Do I have a catch-22 here,
or can it be done?

Thanks to all...
Apr 3 '07 #2
Hello,

does this help?

http://www.ben-rush.net/blog/PermaLi...4221a6b&dotnet.

Ben
http://www.ben-rush.net/blog

On Apr 3, 4:17 pm, "John Kotuby" <j...@powerlist.comwrote:
Hi all,

My application consists of a MasterPage which is used for all WebForms. I
then create UserControls to populate the content area for the different
WebForms.

In one complicated UserControl I have a number of Javscript functions.
Everything on the page works fine, until I try to add the OnLoad event
attribute to the Body tag which is generated by the Master Page.

I want to call a Javascript function upon Load of the page, but not for all
webforms, because only this particular control has the function declared.

How can I add the attribute from the code-behind of the User Control? I
can't add it in the declaration in the Master Page, because only one form
contains the code. Also, the JS Function references other document elements
that only reside in the particualr UserControl. Do I have a catch-22 here,
or can it be done?

Thanks to all...

Apr 4 '07 #3
Thanks for the tip Peter...

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:F0**********************************@microsof t.com...
Try emitting the window.onload =functionname; convention instead. It works
the same.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"John Kotuby" wrote:
>Hi all,

My application consists of a MasterPage which is used for all WebForms. I
then create UserControls to populate the content area for the different
WebForms.

In one complicated UserControl I have a number of Javscript functions.
Everything on the page works fine, until I try to add the OnLoad event
attribute to the Body tag which is generated by the Master Page.

I want to call a Javascript function upon Load of the page, but not for
all
webforms, because only this particular control has the function declared.

How can I add the attribute from the code-behind of the User Control? I
can't add it in the declaration in the Master Page, because only one form
contains the code. Also, the JS Function references other document
elements
that only reside in the particualr UserControl. Do I have a catch-22
here,
or can it be done?

Thanks to all...

Apr 4 '07 #4
Many thanks Ben,

The code works just fine. You have saved me a bunch of time on a tight
schedule....

<kw*****@yahoo.comwrote in message
news:11*********************@y66g2000hsf.googlegro ups.com...
Hello,

does this help?

http://www.ben-rush.net/blog/PermaLi...4221a6b&dotnet.

Ben
http://www.ben-rush.net/blog

On Apr 3, 4:17 pm, "John Kotuby" <j...@powerlist.comwrote:
>Hi all,

My application consists of a MasterPage which is used for all WebForms. I
then create UserControls to populate the content area for the different
WebForms.

In one complicated UserControl I have a number of Javscript functions.
Everything on the page works fine, until I try to add the OnLoad event
attribute to the Body tag which is generated by the Master Page.

I want to call a Javascript function upon Load of the page, but not for
all
webforms, because only this particular control has the function declared.

How can I add the attribute from the code-behind of the User Control? I
can't add it in the declaration in the Master Page, because only one form
contains the code. Also, the JS Function references other document
elements
that only reside in the particualr UserControl. Do I have a catch-22
here,
or can it be done?

Thanks to all...


Apr 4 '07 #5
You're very welcome.

--
~~~~~~~~~~~
Ben Rush
http://www.ben-rush.net/blog
"John Kotuby" <jo***@powerlist.comwrote in message
news:eR**************@TK2MSFTNGP03.phx.gbl...
Many thanks Ben,

The code works just fine. You have saved me a bunch of time on a tight
schedule....

<kw*****@yahoo.comwrote in message
news:11*********************@y66g2000hsf.googlegro ups.com...
>Hello,

does this help?

http://www.ben-rush.net/blog/PermaLi...4221a6b&dotnet.

Ben
http://www.ben-rush.net/blog

On Apr 3, 4:17 pm, "John Kotuby" <j...@powerlist.comwrote:
>>Hi all,

My application consists of a MasterPage which is used for all WebForms.
I
then create UserControls to populate the content area for the different
WebForms.

In one complicated UserControl I have a number of Javscript functions.
Everything on the page works fine, until I try to add the OnLoad event
attribute to the Body tag which is generated by the Master Page.

I want to call a Javascript function upon Load of the page, but not for
all
webforms, because only this particular control has the function
declared.

How can I add the attribute from the code-behind of the User Control? I
can't add it in the declaration in the Master Page, because only one
form
contains the code. Also, the JS Function references other document
elements
that only reside in the particualr UserControl. Do I have a catch-22
here,
or can it be done?

Thanks to all...



Apr 5 '07 #6

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

Similar topics

5
by: Mike Hnatt | last post by:
I'd like the focus to be on "mycontrol" when the page is first loaded. I'm getting an undefined error and am assuming that I can't do this in the body ONLOAD event because the control is not yet...
2
by: Bender | last post by:
Hi, I am wanting to capture an onmousedown event without firing the body tags onload event. Also, if anyone could explain why this happens that would be excellent. I can't see how an...
8
by: alanstew | last post by:
With the body tag calling out 'window onload', a function with a 'window.open' fails at the 'window.open' line. If I cut out the body tag, the function executes as normal. At first I thought it...
5
by: Emmanuel Papillon | last post by:
Hello. I've got a page with sound through a swf file, working with an animation with preloaded JPEG files (animated through use of setTimeout). I'm preloading the JPEG files through Javascript...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
by: Roger | last post by:
How do I add an onload attribute to the body of webpage dynamically?
6
by: tshad | last post by:
Is there a way during Page_Load to change or add an attribute to the Body tag? I want to be able to change the onLoad body attribute to do a focus on one of my text boxes, such as: ...
5
by: mazdotnet | last post by:
Hi, I have a master file with the following setting <body runat="server" id="Body"> and in the .cs I have Body.Attributes.Add("onload", "menuCurrentPage('current','navlist');"); Now in one...
3
by: tshad | last post by:
In VS 2005, I need to get access to the body tag which I have set up on my Master Page as: <body ID="MyBody" runat="server"> But when do something like: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.