3

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.

2 Answers 2

4

Use ClientScriptManager.RegisterStartupScript, which registers a block of JavaScript to execute when the page loads.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use ScriptManager.RegisterClientScriptBlock to invoke JS event:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.