473,386 Members | 1,758 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.

Is there a javascript event that will always fire upon postback?

I would like to do some client side stuff whenever my page is posting
back. My page has a lot of different buttons and links that will cause
a postback. I would rather not have to put something in each of their
"onclick" functions. I would rather have a global OnPostback function
or something like that. I tried using the form's onsubmit function,
but it only gets called when my buttons are clicked; it doesn't get
called when a link gets clicked or a dropdown list causes a postback.
I noticed that these things call the ASP.NET javascript function
__doPostBack. I don't know if I could somehow modify the __doPostBack
function to call my function that does stuff before a postback. Any
ideas?
thanks in advance.
Nov 18 '05 #1
5 4875
Try:

document.MyForm.submit();

within one of your client side DOM object's onClick event procedure.

--
Peter O'Reilly
Nov 18 '05 #2
Try:

document.MyForm.submit();

within one of your client side DOM object's onClick event procedure.

--
Peter O'Reilly
Nov 18 '05 #3

The easiest way I know (it's a hack) is to forward the _doPostBack to my own function and do what I
need in that new function then call _doPostBack (make sure you always force a the _doPostBack
generation on a page, the framework is clever enough to not include it sometimes).

Something like:
<script language="javascript">
<!--
function MyDoPostBack(eventTarget, eventArgument)
{ // do local stuff
if (theform.onsubmit == null || theform.onsubmit()) {
return __oldPostBack(eventTarget, eventArgument);
}
}
var __oldPostBack = __doPostBack;
__doPostBack = MyDoPostBack;
// -->
</script>
Scott

"john" <jo********@yahoo.com> wrote in message
news:29**************************@posting.google.c om...
I would like to do some client side stuff whenever my page is posting
back. My page has a lot of different buttons and links that will cause
a postback. I would rather not have to put something in each of their
"onclick" functions. I would rather have a global OnPostback function
or something like that. I tried using the form's onsubmit function,
but it only gets called when my buttons are clicked; it doesn't get
called when a link gets clicked or a dropdown list causes a postback.
I noticed that these things call the ASP.NET javascript function
__doPostBack. I don't know if I could somehow modify the __doPostBack
function to call my function that does stuff before a postback. Any
ideas?
thanks in advance.

Nov 18 '05 #4

The easiest way I know (it's a hack) is to forward the _doPostBack to my own function and do what I
need in that new function then call _doPostBack (make sure you always force a the _doPostBack
generation on a page, the framework is clever enough to not include it sometimes).

Something like:
<script language="javascript">
<!--
function MyDoPostBack(eventTarget, eventArgument)
{ // do local stuff
if (theform.onsubmit == null || theform.onsubmit()) {
return __oldPostBack(eventTarget, eventArgument);
}
}
var __oldPostBack = __doPostBack;
__doPostBack = MyDoPostBack;
// -->
</script>
Scott

"john" <jo********@yahoo.com> wrote in message
news:29**************************@posting.google.c om...
I would like to do some client side stuff whenever my page is posting
back. My page has a lot of different buttons and links that will cause
a postback. I would rather not have to put something in each of their
"onclick" functions. I would rather have a global OnPostback function
or something like that. I tried using the form's onsubmit function,
but it only gets called when my buttons are clicked; it doesn't get
called when a link gets clicked or a dropdown list causes a postback.
I noticed that these things call the ASP.NET javascript function
__doPostBack. I don't know if I could somehow modify the __doPostBack
function to call my function that does stuff before a postback. Any
ideas?
thanks in advance.

Nov 18 '05 #5
Thanks for the response. I actually found a couple of javascript
events that fire when i want them to: onstop and onbeforeunload. But
they might only be available for IE.
Nov 18 '05 #6

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

Similar topics

2
by: john | last post by:
I would like to do some client side stuff whenever my page is posting back. My page has a lot of different buttons and links that will cause a postback. I would rather not have to put something in...
6
by: tshad | last post by:
I am trying to set up a Javascript popup box that has a way of sending back a message to asp.net on how to process some data. At the moment I am just doing: ...
5
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze...
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$) { } ...
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:
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
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,...
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.