编程语言
首页 > 编程语言> > How to intercept any postback in a page? - ASP.NET

How to intercept any postback in a page? - ASP.NET

作者:互联网

How to intercept any postback in a page? - ASP.NET

There's a couple of things you can do to intercept a postback on the client.

The __doPostBack function looks like this:

function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}

方案1

Notice that it calls "theForm.onsubmit()" before actually doing the postback. This means that if you assign your form an onsubmit javascript function, it will always be called before every postback.

<form id="form1" runat="server" onsubmit="return myFunction()">

方案2

Alternately, you can actually override the __doPostBack function and replace it with your own. This is an old trick that was used back in ASP.Net 1.0 days.

var __original= __doPostBack;
__doPostBack = myFunction();

This replaces the __doPostBack function with your own, and you can call the original from your new one.

 

 

 

Using JQuery to intercept the click of an ASP:Button

 

 

 

 

标签:__,function,ASP,postback,theForm,doPostBack,page
来源: https://www.cnblogs.com/chucklu/p/11190331.html