473,326 Members | 2,126 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,326 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 4870
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.