2013-01-11 33 views
3

我有一個「支付」按鈕,我們開始接受信用卡。我需要從服務器端點擊事件調用一個Javascript函數。我嘗試使用Response.Write,如下所示,但不會觸發我單獨的.js文件中定義的函數。我還可以做些什麼?有條件地調用JavaScript函數

 protected void btmMakePayment_Click(object sender, EventArgs e) 
     {    
      if (user selected credit card) 
      { 
       Response.Write("<script language='javascript' type='text/javascript'>OpenPayPalDialog();</script>"); 
      } 
      else 
      { 
       continue with the current server side logic 
      } 
     } 

謝謝您提前。

回答

1

您可以使用ScriptManager.RegisterClientScriptBlock調用JS事件:

ScriptManager.RegisterClientScriptBlock(this, typeof(this), "JSKey", "JSFunctionName(<param>);", true);