关于回调注册客户端脚本

当你的页面或控件实现了接口ICallbackEventHandler

其成员有

// 摘要:
    //     用于指示控件可以作为服务器上的回调事件的目标。
    public interface ICallbackEventHandler
    {
        // 摘要:
        //     返回以控件为目标的回调事件的结果。
        //
        // 返回结果:
        //     回调的结果。
        string GetCallbackResult();
        //
        // 摘要:
        //     处理以控件为目标的回调事件。
        //
        // 参数:
        //   eventArgument:
        //     一个字符串,表示要传递到事件处理程序的事件参数。
        void RaiseCallbackEvent(string eventArgument);
    }

当在页面加载的时候注册

ClientScript.GetCallbackEventReference(this, "arg", "callback", "context");

系统将自动在客户端注册了代码:

<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />


<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm
= document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
   
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value
= eventTarget;
        theForm.__EVENTARGUMENT.value
= eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<script src="/LotteryAnalysis.Web/WebResource.axd?d=X6NylRAXvpzvfgJ_INjMzQ2&amp;t=633764603620000000" type="text/javascript"></script>

<script type="text/javascript">
//<![CDATA[

WebForm_InitCallback();
//]]>
</script>

原文地址:https://www.cnblogs.com/samlin/p/1488536.html