473,779 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does the ASP.Net Panel client side onLoad work?

I'm trying to create a web page and I need a javascript function to be called
on the load of a particular panel. (The panel is hidden during some but not
all postbacks.)

The function is bound to the panel in VB as follows:

pnlAdd.Attribut es.Add("onLoad" , "SetupScreenLit e()")

This is basically how we attach all functions in our projects but this is
the first time I've worked with onLoad and the first time I've tried to
attach anything to a panel. Any ideas?
Feb 19 '06 #1
17 6446
"=?Utf-8?B?Qi4gQ2hlcm5 pY2s=?="
<BC*******@disc ussions.microso ft.com> wrote in
news:DE******** *************** ***********@mic rosoft.com:
I'm trying to create a web page and I need a javascript function
to be called on the load of a particular panel. (The panel is
hidden during some but not all postbacks.)

The function is bound to the panel in VB as follows:

pnlAdd.Attribut es.Add("onLoad" , "SetupScreenLit e()")

This is basically how we attach all functions in our projects
but this is the first time I've worked with onLoad and the first
time I've tried to attach anything to a panel. Any ideas?

The panel control generates a <DIV> tag. That tag does not support
the onload event:

http://msdn.microsoft.com/workshop/a...bjects/div.asp

In fact, the onload event is valid for only a small selection of
HTML tags:

http://msdn.microsoft.com/workshop/a...nts/onload.asp

Using the page's RegisterStartup Script method may be an
alternative way to achieve your goal.
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Feb 19 '06 #2
Ok, the problem is this. I am a relative beginner in Javascript. I am
trying to develop an ASP.net 1.1 web page. I need a way for a Javascript
function to fire once after the load of the page into the browser. What are
my options?

"Chris R. Timmons" wrote:
"=?Utf-8?B?Qi4gQ2hlcm5 pY2s=?="
<BC*******@disc ussions.microso ft.com> wrote in
news:DE******** *************** ***********@mic rosoft.com:
I'm trying to create a web page and I need a javascript function
to be called on the load of a particular panel. (The panel is
hidden during some but not all postbacks.)

The function is bound to the panel in VB as follows:

pnlAdd.Attribut es.Add("onLoad" , "SetupScreenLit e()")

This is basically how we attach all functions in our projects
but this is the first time I've worked with onLoad and the first
time I've tried to attach anything to a panel. Any ideas?

The panel control generates a <DIV> tag. That tag does not support
the onload event:

http://msdn.microsoft.com/workshop/a...bjects/div.asp

In fact, the onload event is valid for only a small selection of
HTML tags:

http://msdn.microsoft.com/workshop/a...nts/onload.asp

Using the page's RegisterStartup Script method may be an
alternative way to achieve your goal.
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Feb 19 '06 #3
add the onload attribute to the page's BODY tag:

<BODY onload="myJsFun ction();" >

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"B. Chernick" wrote:
Ok, the problem is this. I am a relative beginner in Javascript. I am
trying to develop an ASP.net 1.1 web page. I need a way for a Javascript
function to fire once after the load of the page into the browser. What are
my options?

"Chris R. Timmons" wrote:
"=?Utf-8?B?Qi4gQ2hlcm5 pY2s=?="
<BC*******@disc ussions.microso ft.com> wrote in
news:DE******** *************** ***********@mic rosoft.com:
I'm trying to create a web page and I need a javascript function
to be called on the load of a particular panel. (The panel is
hidden during some but not all postbacks.)

The function is bound to the panel in VB as follows:

pnlAdd.Attribut es.Add("onLoad" , "SetupScreenLit e()")

This is basically how we attach all functions in our projects
but this is the first time I've worked with onLoad and the first
time I've tried to attach anything to a panel. Any ideas?

The panel control generates a <DIV> tag. That tag does not support
the onload event:

http://msdn.microsoft.com/workshop/a...bjects/div.asp

In fact, the onload event is valid for only a small selection of
HTML tags:

http://msdn.microsoft.com/workshop/a...nts/onload.asp

Using the page's RegisterStartup Script method may be an
alternative way to achieve your goal.
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Feb 19 '06 #4
"=?Utf-8?B?Qi4gQ2hlcm5 pY2s=?="
<BC*******@disc ussions.microso ft.com> wrote in
news:B3******** *************** ***********@mic rosoft.com:
Ok, the problem is this. I am a relative beginner in
Javascript. I am trying to develop an ASP.net 1.1 web page. I
need a way for a Javascript function to fire once after the load
of the page into the browser. What are my options?


As Peter noted, the onload attribute of the <BODY> tag can be
used, as can the RegisterStartup Script method.

Personally, I prefer to use RegisterStartup Script. It's
possible that some browsers have buggy implementations of
onload, plus I can insert as much JavaScript as I want
with RegisterStartup Script. JavaScript inserted into the
onload attribute is realistically limited to method calls and
short segments of code that can be expressed in one line.

More info on client-side scripting w/ ASP.Net:

http://msdn.microsoft.com/library/de...sidescript.asp
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Feb 19 '06 #5
You refer to 'buggy implementations of onload'.

Could this, in practice, result in one or more web controls appearing as
nulls (and crashing the script) when the onload function fires, even if the
controls have been 'wired' into the Javascript in a conventional fashion?
(i.e. document.getEle mentById("<%= {control-name}.ClientID %>");

"Chris R. Timmons" wrote:
"=?Utf-8?B?Qi4gQ2hlcm5 pY2s=?="
<BC*******@disc ussions.microso ft.com> wrote in
news:B3******** *************** ***********@mic rosoft.com:
Ok, the problem is this. I am a relative beginner in
Javascript. I am trying to develop an ASP.net 1.1 web page. I
need a way for a Javascript function to fire once after the load
of the page into the browser. What are my options?


As Peter noted, the onload attribute of the <BODY> tag can be
used, as can the RegisterStartup Script method.

Personally, I prefer to use RegisterStartup Script. It's
possible that some browsers have buggy implementations of
onload, plus I can insert as much JavaScript as I want
with RegisterStartup Script. JavaScript inserted into the
onload attribute is realistically limited to method calls and
short segments of code that can be expressed in one line.

More info on client-side scripting w/ ASP.Net:

http://msdn.microsoft.com/library/de...sidescript.asp
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Feb 20 '06 #6
A worse problem, or perhaps I have misstated the problem. I was testing with
the body onload event and it appears that this event only fires once on
initial load and does not fire on postbacks. I was assuming otherwise. I
need an event that fires on every postback.

"Chris R. Timmons" wrote:
"=?Utf-8?B?Qi4gQ2hlcm5 pY2s=?="
<BC*******@disc ussions.microso ft.com> wrote in
news:B3******** *************** ***********@mic rosoft.com:
Ok, the problem is this. I am a relative beginner in
Javascript. I am trying to develop an ASP.net 1.1 web page. I
need a way for a Javascript function to fire once after the load
of the page into the browser. What are my options?


As Peter noted, the onload attribute of the <BODY> tag can be
used, as can the RegisterStartup Script method.

Personally, I prefer to use RegisterStartup Script. It's
possible that some browsers have buggy implementations of
onload, plus I can insert as much JavaScript as I want
with RegisterStartup Script. JavaScript inserted into the
onload attribute is realistically limited to method calls and
short segments of code that can be expressed in one line.

More info on client-side scripting w/ ASP.Net:

http://msdn.microsoft.com/library/de...sidescript.asp
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Feb 20 '06 #7
"=?Utf-8?B?Qi4gQ2hlcm5 pY2s=?="
<BC*******@disc ussions.microso ft.com> wrote in
news:86******** *************** ***********@mic rosoft.com:
You refer to 'buggy implementations of onload'.

Could this, in practice, result in one or more web controls
appearing as nulls (and crashing the script) when the onload
function fires, even if the controls have been 'wired' into the
Javascript in a conventional fashion? (i.e.
document.getEle mentById("<%= {control-name}.ClientID %>");


I don't think so. Is that line of JavaScript before or after the
control in question? The control needs to appear before the
JavaScript that accesses it so the browser can put the control in the
page's document object model (DOM) tree.

For example, this HTML will generate an "object required" error
message, because the <INPUT> control comes after the JavaScript
that's trying to access that control's value:

<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT>
var value = document.getEle mentById("myInp utBox").value;
alert(value);
</SCRIPT>
<INPUT type="text" id="myInputBox " name="myInputBo x"
value="Hello, world!"/>
</BODY>
</HTML>

But placing the <INPUT> control before the JavaScript will work:

<HTML>
<HEAD>
</HEAD>
<BODY>
<INPUT type="text" id="myInputBox " name="myInputBo x"
value="Hello, world!"/>
<SCRIPT>
var value = document.getEle mentById("myInp utBox").value;
alert(value);
</SCRIPT>
</BODY>
</HTML>

This is where the RegisterStartup Script method comes in handy. It
always places the JavaScript at the very end of the HTML, just before
the closing </FORM> tag.

If that's not the problem, what might be happening is either "name
mangling" of the ClientID by ASP.Net, or a known bug in .Net 1.1:

http://support.microsoft.com/default.aspx?id=818803

Concerning name mangling, when multiple instances of the same user
control are present on a page, they cannot all have the same ID in
the generated HTML page. Therefore, ASP.Net gives each instance of
the control a unique name when it generates the HTML.

A control named BlogSideBar1, with an embedded textbox named
SearchBox, would be referenced by C#/VB in an .ascx file as
BlogSideBar1.Se archBox. However, in the HTML it would appear as
_ctl0____ctl0__ _BlogSideBar1__ _SearchBox.

Your line of code should work, depending on when it's executed in the
page's life cycle on the server. If there are multiple instances of
"control-name" in your page, that situation might be causing some
kind of problem.

I generally don't put inline <% %> tags in my pages, except for
mundane things like the page's title or meta tags. I prefer to build
the JavaScript, complete with ClientIDs, in my code behind files.
That way I feel I have better control over exactly what gets sent to
the browser, and where it's placed in the page.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Feb 21 '06 #8
"=?Utf-8?B?Qi4gQ2hlcm5 pY2s=?="
<BC*******@disc ussions.microso ft.com> wrote in
news:E2******** *************** ***********@mic rosoft.com:
A worse problem, or perhaps I have misstated the problem. I was
testing with the body onload event and it appears that this
event only fires once on initial load and does not fire on
postbacks. I was assuming otherwise. I need an event that fires
on every postback.


Are you assigning the value to the onload event in the page's
Page_Load event? If so, is that assignment in an if/then statement
that uses IsPostBack?

It sounds like what's happening is this:

::In the Page_Load event::

if not IsPostBack then
assign value to <BODY> onload
end if

The fix is to move the onload assignment outside of that if/then
block, so it's always executed when the page is initially created,
and after every postback.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Feb 21 '06 #9
Thanks, but help me out a little more (Javascript beginner, remember?) I'm
drawing a blank.

When you say 'assign value to <BODY> onload' , are you referring to
something like RegisterStartUp Script or is this yet another Javascript
technique I haven't seen yet?

"Chris R. Timmons" wrote:
"=?Utf-8?B?Qi4gQ2hlcm5 pY2s=?="
<BC*******@disc ussions.microso ft.com> wrote in
news:E2******** *************** ***********@mic rosoft.com:
A worse problem, or perhaps I have misstated the problem. I was
testing with the body onload event and it appears that this
event only fires once on initial load and does not fire on
postbacks. I was assuming otherwise. I need an event that fires
on every postback.


Are you assigning the value to the onload event in the page's
Page_Load event? If so, is that assignment in an if/then statement
that uses IsPostBack?

It sounds like what's happening is this:

::In the Page_Load event::

if not IsPostBack then
assign value to <BODY> onload
end if

The fix is to move the onload assignment outside of that if/then
block, so it's always executed when the page is initially created,
and after every postback.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Feb 21 '06 #10

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

Similar topics

6
5198
by: Ben Fitzgerald | last post by:
Hi I feel I'll be asking for someone to turn water into wine before this happens, but just in case! I'd like to have a page that provides a basic xml document with an xslt that defines the default sorting. Say it's in a table sorted by name with columns age and height. Then, when the user clicks on another column heading, this
0
2956
by: Daisy | last post by:
Is there any way in an ascx (without resorting to a codebehind file) to have a client-side onload event on an asp:image tag? I've just changed from a normal image, to an asp:image tag, but now it tries to interpret my javascript server-side :-\ <asp:Image runat="server" ImageUrl="a" onload="LoadImage(this);"></asp:Image> :-((
3
2963
by: todd | last post by:
Hi all. I inherited this code from a contractor. It is a .NET user control that runs on the client side (ie) on machines with the framework installed. I have been mucking around to get it work for a couple of days now, and am growign really frustrated. I need to expose an Import method on the ImportControl and have it accesible to javascrip in the browser. If I remove the InterfaceType and ClassInterface attributes, compile and then...
1
2934
by: Hal | last post by:
My most sincere gratitude to anyone who can help me work around this! I have work that needs to be done in javascript on the client whenever a page is unloaded. To this end, I subscribe to the unload event (client side not server side) of the <body> HTML element through javascript.
2
1392
by: MonkeyBoy | last post by:
I am doing some some HTML manipulation in client-side script (IE5.x and IE6.x browsers only). Something like.. var tmpHTML = oTable.outerHTML // do something to the HTML her oTable.outerHTML = tmpHTML Before the changes, client-side .Net field validators (RegularExpressionValidator, RangeValidator, etc.) work fine... after the changes, the modified HTML works correctly but the validators stop functioning. Seems that the onchange handler...
1
2408
by: Oleg Ogurok | last post by:
Hi all, I have a small image ("Loading..." icon) that I hide using Javascript once the page finishes loading. To do so, I attach to the client side onload event. However, as soon as I turn on Smart Navigation, the onload event no longer fires on postbacks. Any idea? <script language=javascript>
0
1220
by: NH | last post by:
I know how to make client side paging work in the gridiew control using a sqlDataSource (and it works great!). But how can I "code" this i.e. I want to use a dataset as the datasource of the gridview. I have a stored procedure that returns data based on what parameter is passed in to it from the page load event of an asp.net form and then I want to bind the gridview to this dataset. But how can I use client cide paging in this context? ...
2
1426
by: MPA | last post by:
Hi, I am a newbee. All our applications so far were traditional client-server database applications. We are considering now writing our main application with Visual Studio .NET. Basically we want to be able to install each version of our software on one or two machines without having to meddle with typically several hundred client computers. We understand that using the new architecture we write server side code in C# or Visual Basic,...
8
2187
by: MAX2006 | last post by:
Hi, I am doing some client side javascipt work. I have a handler for window.onUnload event and within the code; I need to know the name of the asp.net button caused the postback. How can I do that? Thank you Max
0
9632
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
10302
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...
1
10071
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8958
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
6723
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
5372
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...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.