如何在回调函数中传递参数?

时间:2012-08-28 09:39:32

标签: javascript asp.net callback

我想在回调中获取电子邮件(来自txtEmail字段的文本值)

我有文字字段:

  <asp:TextBox MaxLength="50" runat="server" ID="txtEmail" ClientIDMode="Static" onblur="SendRequest()"></asp:TextBox>

我的javascript处理程序:

 <script type="text/javascript">
      function SendRequest(arg) {
           window.UseCallback(arg);
      }
 </script>

和服务器事件处理程序

 protected void Page_Init(object sender, EventArgs e)
 {
    string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "GetEmailFromServer", "context");
    string cbScript = "function UseCallback(arg, context){" + cbReference + ";}";
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallback", cbScript, true);
 }

 public void RaiseCallbackEvent(string eventArg)
 {
     var result = Controller.CheckEmail(eventArg);      // eventArg == undefined
 }

如何将eventArg设置为txtEmail.Text?

1 个答案:

答案 0 :(得分:0)

更改此行并检查

 string cbScript = "function UseCallback(arg){" + cbReference + ";}"; 

更改此

<script type="text/javascript">        
       function SendRequest(arg) 
        {
             window.UseCallback(arg,"");
        }   
</script>