如何拦截在页面回发任何? - ASP.NET [英] How to intercept any postback in a page? - ASP.NET
问题描述
我要截取当前页面的的回传之前的它发生。我想要做一些自定义的操作回传送达前。任何想法如何做到这一点?
I want to intercept any postbacks in the current page BEFORE it occurs . I want to do some custom manipulation before a postback is served. Any ideas how to do that?
推荐答案
有一对夫妇的事情可以做,拦截客户端上的回发。
There's a couple of things you can do to intercept a postback on the client.
该__doPostBack函数如下:
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();
}
}
请注意,它调用theForm.onsubmit()之前,实际上做回发。这意味着,如果您将其分配形式的onsubmit的javascript函数,它总是会回发的每个之前调用。
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()">
另外,你其实可以覆盖__doPostBack功能,并用自己的替换它。这是用于早在ASP.Net1.0天一个老把戏。
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();
此替换自己的__doPostBack功能,你可以从你的新调用原来的。
This replaces the __doPostBack function with your own, and you can call the original from your new one.
这篇关于如何拦截在页面回发任何? - ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!