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

WhiteSpider
  • 385
  • 1
  • 3
  • 10
  • Check this http://stackoverflow.com/questions/27917255/c-sharp-web-method-is-not-calling-in-javascript/27917333#27917333 – Mairaj Ahmad May 04 '15 at 09:49
  • You need to return something from that function ? – Tushar Gupta May 04 '15 at 09:49
  • Hi Mairaj I did have a look but need to call my method from inside the function when the customer clicks confirm – WhiteSpider May 04 '15 at 11:10
  • can you provide your [WebMethod] code? also, why can't you just hook the javascript to the confirm click? – terbubbs May 04 '15 at 12:17
  • Also have you checked the javascript with Firebug or Chrome? – terbubbs May 04 '15 at 12:17
  • well first make sure you are setting up the [WebMethod] correctly using the link Mairaj provided.. second, is the confirm click an asp control? just reference the button click in your script: <%= btn_Confirm.ClientId %>.click() or something similar... – terbubbs May 04 '15 at 12:26
  • Also please check Firebug or Chrome... if you get a 404 when it tries to call the .ajax then that means it isn't set up right because it is not found.. if you get 500, then typically there's something wrong with the actual WebMethod – terbubbs May 04 '15 at 12:27
  • The confirm click is on the javascript popup box – WhiteSpider May 04 '15 at 13:22

0 Answers0