473,385 Members | 2,243 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,385 software developers and data experts.

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.Attributes.Add("onLoad", "SetupScreenLite()")

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 6405
"=?Utf-8?B?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:DE**********************************@microsof t.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.Attributes.Add("onLoad", "SetupScreenLite()")

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 RegisterStartupScript 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?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:DE**********************************@microsof t.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.Attributes.Add("onLoad", "SetupScreenLite()")

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 RegisterStartupScript 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="myJsFunction();" >

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?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:DE**********************************@microsof t.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.Attributes.Add("onLoad", "SetupScreenLite()")

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 RegisterStartupScript 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?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:B3**********************************@microsof t.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 RegisterStartupScript method.

Personally, I prefer to use RegisterStartupScript. It's
possible that some browsers have buggy implementations of
onload, plus I can insert as much JavaScript as I want
with RegisterStartupScript. 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.getElementById("<%= {control-name}.ClientID %>");

"Chris R. Timmons" wrote:
"=?Utf-8?B?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:B3**********************************@microsof t.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 RegisterStartupScript method.

Personally, I prefer to use RegisterStartupScript. It's
possible that some browsers have buggy implementations of
onload, plus I can insert as much JavaScript as I want
with RegisterStartupScript. 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?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:B3**********************************@microsof t.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 RegisterStartupScript method.

Personally, I prefer to use RegisterStartupScript. It's
possible that some browsers have buggy implementations of
onload, plus I can insert as much JavaScript as I want
with RegisterStartupScript. 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?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:86**********************************@microsof t.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.getElementById("<%= {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.getElementById("myInputBox").value;
alert(value);
</SCRIPT>
<INPUT type="text" id="myInputBox" name="myInputBox"
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="myInputBox"
value="Hello, world!"/>
<SCRIPT>
var value = document.getElementById("myInputBox").value;
alert(value);
</SCRIPT>
</BODY>
</HTML>

This is where the RegisterStartupScript 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.SearchBox. 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?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:E2**********************************@microsof t.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 RegisterStartUpScript or is this yet another Javascript
technique I haven't seen yet?

"Chris R. Timmons" wrote:
"=?Utf-8?B?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:E2**********************************@microsof t.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
On second thought, are you refering to giving the body an ID, declaring it in
the codebehind, and then doing an <idname>.Attributes.Add("onLoad" etc?

Just found an example and I can see it in the HTML source but it doesn't fire.

"Chris R. Timmons" wrote:
"=?Utf-8?B?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:E2**********************************@microsof t.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 #11
Sorry about the number of appends. I moved my code up in the Page_Load
codebehind so that it always gets called but the HTML code only fires the
first time, never on postback. (but I can still see it in the HTML source)

"Chris R. Timmons" wrote:
"=?Utf-8?B?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:E2**********************************@microsof t.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 #12
"=?Utf-8?B?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:C6**********************************@microsof t.com:
Sorry about the number of appends. I moved my code up in the
Page_Load codebehind so that it always gets called but the HTML
code only fires the first time, never on postback. (but I can
still see it in the HTML source)


That sounds strange. Could you post some code that demonstrates the
problem?

Thanks.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Feb 21 '06 #13
"=?Utf-8?B?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:33**********************************@microsof t.com:
On second thought, are you refering to giving the body an ID,
declaring it in the codebehind, and then doing an
<idname>.Attributes.Add("onLoad" etc?
Yes.

The body tag should look something like this in the .aspx file:

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

Declare it as an HtmlControl in the code behind file:

protected System.Web.UI.HtmlControls.HtmlGenericControl body;

And the onload attribute can be assigned like this in the Page_Load
event handler:

this.body.Attributes["onload"] = "alert('Hello, world!');";
Just found an example and I can see it in the HTML source but it
doesn't fire.


Does the body tag have the runat="server" attribute?

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Feb 21 '06 #14
Not much to show.

In my aspx file I have <body id="body1" runat="server" >

In my vb file I have the declaration: ' Protected WithEvents body1 As
HtmlGenericControl' (I have tried this both with and without the WithEvents
declaration. It apparently has no effect on results.)

In the page_load (above the usual test for postback, so it's always called)
I have: 'body1.Attributes.Add("onLoad", "alert('test');")'

In the HTML source of the postback screen I see: '<body id="body1"
onLoad="alert('test');">'

But it never fires except on the very first time.

"Chris R. Timmons" wrote:
"=?Utf-8?B?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:C6**********************************@microsof t.com:
Sorry about the number of appends. I moved my code up in the
Page_Load codebehind so that it always gets called but the HTML
code only fires the first time, never on postback. (but I can
still see it in the HTML source)


That sounds strange. Could you post some code that demonstrates the
problem?

Thanks.

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

Feb 21 '06 #15
"B. Chernick" wrote:
Not much to show.

In my aspx file I have <body id="body1" runat="server" >

In my vb file I have the declaration: ' Protected WithEvents body1 As
HtmlGenericControl' (I have tried this both with and without the WithEvents
declaration. It apparently has no effect on results.)

In the page_load (above the usual test for postback, so it's always called)
I have: 'body1.Attributes.Add("onLoad", "alert('test');")'

In the HTML source of the postback screen I see: '<body id="body1"
onLoad="alert('test');">'

But it never fires except on the very first time.


I'm pretty much out of ideas. If possible, could you post a complete .aspx
page that demonstrates the problem?

Thanks.

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

Feb 21 '06 #16
I should apologize for wasting your time. I've been looking in the wrong
place. If you set up a test screen with only the code I have described it
works perfectly every time. I suspect that the third party (Telerik)
controls we're using are somehow interfering with the postback.

"Chris R. Timmons" wrote:
"B. Chernick" wrote:
Not much to show.

In my aspx file I have <body id="body1" runat="server" >

In my vb file I have the declaration: ' Protected WithEvents body1 As
HtmlGenericControl' (I have tried this both with and without the WithEvents
declaration. It apparently has no effect on results.)

In the page_load (above the usual test for postback, so it's always called)
I have: 'body1.Attributes.Add("onLoad", "alert('test');")'

In the HTML source of the postback screen I see: '<body id="body1"
onLoad="alert('test');">'

But it never fires except on the very first time.


I'm pretty much out of ideas. If possible, could you post a complete .aspx
page that demonstrates the problem?

Thanks.

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

Feb 21 '06 #17
"=?Utf-8?B?Qi4gQ2hlcm5pY2s=?="
<BC*******@discussions.microsoft.com> wrote in
news:38**********************************@microsof t.com:
I should apologize for wasting your time. I've been looking in
the wrong place. If you set up a test screen with only the code
I have described it works perfectly every time. I suspect that
the third party (Telerik) controls we're using are somehow
interfering with the postback.


No problem.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Feb 21 '06 #18

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

Similar topics

6
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...
0
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...
3
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...
1
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...
2
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 =...
1
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...
0
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...
2
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...
8
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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.