Click here to Skip to main content
15,908,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I call web method , in asp.net from jquery ajax post
and want to show alert box or popup from web method and then window.location.href = "#" to be at same page

click button is as box from jquery on which click, i call web method



how to do this
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jan-14 1:21am    
What do you mean by "alert box from web method"? Alert box in on the client side, and the method is executed on the server side. Maybe, out of the method result returned? Then what's the problem?
—SA
maulikshah1990 2-Jan-14 1:25am    
i want to show alert box if condition in web method is false , show alert box

1 solution

Aspx code here :
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btnCall").click(function () {
            alert("eded"); 
            $.ajax({
            type: "POST",
            url: "Default.aspx/DoSomething",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                alert(msg.d);
            }
        });
        }); 
    });

</script>

    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <button id="btnCall" type="button">Call Method</button>
    </div>
    </form>
</body>
</html></html>


Do what ever you want in the method success
code behind content:
C#
using System;
using System.Web.Services;
using System.Web.Script.Services;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    [WebMethod]
    [ScriptMethod]
    public static string DoSomething()
    {
        return "sba";
    }

}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900