Thursday, August 30, 2012

Ajax Calls in asp.net

asp:   
function CheckGroupName() {
            var name = $('#<%= txtGroupName.ClientID %>').val();
            $.ajax({
                url: "CreateGroups.aspx/CheckGroupName",   // Current Page, Method 
                data: JSON.stringify({ name: name }), // parameter map as JSON 
                type: "POST", // data has to be POSTed 
                contentType: "application/json", // posting JSON content     
                dataType: "JSON",  // type of data is JSON (must be upper case!) 
                timeout: 10000,    // AJAX timeout 
                success: function (result) {
                    if (result == '{"d":"Yes"}') {
                      
                        alert('Entered Group Name alredy Exists for the account.Please Use a Differenet name to register.');
                        return false;
                    }
                },
                error: function (xhr, status) {
                    alert(status + " - " + xhr.responseText);
                }
            });

        }

aspx.cs:
  [WebMethod]
        public static string CheckGroupName(string name)
        {
            if (Activayt.Business.Group.IsExists(AccountID, name, _parent))
            {
              
                return "Yes";
            }
            else
            {
                return "";
            }
        }

No comments:

Post a Comment