0

I call a javascript pop up after I click a button.

Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "doajax();", true);

This then shows two buttons confirm or cancel.

I need to be able to call a method in my code behind if I click confirm.

<script type="text/javascript">
    function doajax() {
        $.ajax({
            type: "POST",
            url: 'Application.aspx/Function',
            data: "",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                $("#divResult").html("success");
                //I need to call my code behind method here
            },
            error: function (e) {
                $("#divResult").html("Something Wrong.");
            }
        });
    }
    </script>

I have tried several things but nothing hits my method.

Any help would be appreciated.

Grant

8
  • Check this stackoverflow.com/questions/27917255/… Commented May 4, 2015 at 9:49
  • You need to return something from that function ? Commented May 4, 2015 at 9:49
  • Hi Mairaj I did have a look but need to call my method from inside the function when the customer clicks confirm Commented May 4, 2015 at 11:10
  • can you provide your [WebMethod] code? also, why can't you just hook the javascript to the confirm click? Commented May 4, 2015 at 12:17
  • Also have you checked the javascript with Firebug or Chrome? Commented May 4, 2015 at 12:17

0

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.