Click here to Skip to main content
Click here to Skip to main content

Calling a C# method using jQuery on the client side

By , 2 Oct 2011
 
Create a web service name WebMethod.SVC in the CS file and add the method:

[OperationContract]
        [WebInvoke(Method = "POST")]
        public void DeleteRec(string ID)
        {
            DelUser(Convert.ToInt32(ID));
        }
 
On client side, give the path and call the method:
 
function DeleteMessage() {            
            var ID = $('[id$="hdnUserId"]').val();
            var url = '<%=ResolveUrl("~/WebMethods.svc/DeleteRec")%&  gt;';            
            $.ajax({
                type: "POST",
                url: url,
                contentType: "application/json; charset=utf-8",
                data: '{"ID":"' + ID + '"}',
                dataType: "json",
                success: function (response) {
                    document.location.href = '<%= ResolveUrl("~/Test1.aspx")%>';
                },
                error: function (xhr, ajaxOptions, thrownError) {
                }
            });
        }
 
This was the other way which I got.

License

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

About the Author

Anuja Pawar Indore
Technical Lead Diaspark
India India
Member
I have keen interest in learning new things, exploring more on a topic and being more versatile

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1memberRJOberg19 Oct '12 - 3:43 
GeneralRe: My vote of 1memberAnuja Pawar Indore19 Oct '12 - 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 2 Oct 2011
Article Copyright 2011 by Anuja Pawar Indore
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid