Friday, September 14, 2012

Call ASP.NET server side method using jQuery in asp.net

 function UpdateProfile() {

            $.ajax({
                cache: false,
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "webservice.asmx/UpdateProfile",
                data: "{'strAbout':'" + $('#<%=txtAbout.ClientID%>').val()
                    + "','strAddress':'" + $('#<%=txtAddress.ClientID%>').val()
                    + "','strGender':'" + $('#<%=txtGender.ClientID%>').val()
                    + "'}",
                dataType: "json",

                success: function (data) {
                    var coupons = data.d;
                },
                failure: function (msg) {
                    alert(msg);
                }

            });
        }
above code is for jquery call server side method in asp.net or Calling ASP.NET server side method using jQuer.

webservice.asmx.Cs :

 [WebMethod]
    public string UpdateProfile(string strAbout, string strAddress, string strGender)
    {
        userDTO objUserDto = new userDTO();
        objUserDto.ID = Convert.ToInt64(UserID);
        objUserDto.About = strAbout;     
        objUserDto.Gender = strGender;
        objUserDto.Address = strAddress;
        UserService UService = new UserService(new UserRepository());
        UService.UpdateUserProfileLB(objUserDto);
        return "Updated Successfully";
    }

No comments:

Post a Comment

Comments

Search

Custom Search
Protected by Copyscape Plagiarism Software