有条件地调用JavaScript函数

时间:2013-01-11 00:58:09

标签: c# javascript asp.net

我有一个“付款”按钮,我们开始接受信用卡。我需要从服务器端点击事件调用Javascript函数。我尝试使用Response.Write,但不会触发我在单独的.js文件中定义的函数。我还能做什么?

        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
            }
       }

提前谢谢你。

2 个答案:

答案 0 :(得分:4)

使用ClientScriptManager.RegisterStartupScript,它会在页面加载时注册要执行的JavaScript块。

答案 1 :(得分:1)

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

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