Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Calling a C# method using jQuery on the client side

By , 2 Oct 2011
Rate this:
Please Sign up or sign in to vote.
Create a web service name WebMethod.SVC in the CS file and add the method:

        [WebInvoke(Method = "POST")]
        public void DeleteRec(string 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;';            
                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.


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
I have keen interest in learning new things, exploring more on a topic and being more versatile
Follow on   Twitter

Comments and Discussions

GeneralMy vote of 1 PinmemberMarco Bertschi21-Oct-12 23:50 
GeneralRe: My vote of 1 PinmemberAnuja Pawar Indore22-Oct-12 0:04 
GeneralMy vote of 1 Pinmemberihoecken21-Oct-12 22:17 
This is just a code sniplet not an article
GeneralMy vote of 1 Pinmembernagendrathecoder21-Oct-12 20:41 
GeneralMy vote of 1 PinmemberSuresh Suthar21-Oct-12 20:12 
GeneralMy vote of 1 Pinmembersaini arun19-Oct-12 20:02 
GeneralMy vote of 1 PinmemberRJOberg19-Oct-12 3:43 
GeneralRe: My vote of 1 PinmemberAnuja Pawar Indore19-Oct-12 4:31 
GeneralReason for my vote of 4 It's nice Anuja Pinmemberkanjolia gopal22-Nov-11 19:26 
GeneralRe: Thanks Kanjolia :) PinmemberAnuja Pawar Indore22-Nov-11 19:32 
GeneralReason for my vote of 5 Nice ! PinmemberDilip Baboo13-Sep-11 13:12 
GeneralRe: Thanks Dilip PinmemberAnuja Pawar Indore5-Oct-11 3:13 
GeneralReason for my vote of 1 Poor PinmemberBrianBissell13-Sep-11 3:47 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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