Reputation: 1443
I have a "Pay" button where we are starting to accept credit card. I need to call a Javascript function from the server side click event. I tried with Response.Write as below but that does not trigger my function that is defined in the separate .js file. What else can I do?
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
}
}
Thank You in advance.
Upvotes: 3
Views: 831
Reputation: 2732
You can use ScriptManager.RegisterClientScriptBlock to invoke JS event:
ScriptManager.RegisterClientScriptBlock(this, typeof(this), "JSKey", "JSFunctionName(<param>);", true);
Upvotes: 1
Reputation: 6270
Use ClientScriptManager.RegisterStartupScript, which registers a block of JavaScript to execute when the page loads.
Upvotes: 4