Click here to Skip to main content
15,069,133 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick
Posted 8 Sep 2011

Tagged as

Stats

24.6K views
6 bookmarked

Calling a C# method using jQuery on the client side

Rate me:
Please Sign up or sign in to vote.
1.47/5 (14 votes)
2 Oct 2011CPOL
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...
Create a web service name WebMethod.SVC in the CS file and add the method:

C#
[OperationContract]
        [WebInvoke(Method = "POST")]
        public void DeleteRec(string ID)
        {
            DelUser(Convert.ToInt32(ID));
        }


On client side, give the path and call the method:

C#
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)

Share

About the Author

Anuja Pawar Indore
Program Manager Infobeans
India India
I have keen interest in learning new things, exploring more on a topic and being more versatile

Comments and Discussions

 
GeneralMy vote of 1 Pin
Marco Bertschi21-Oct-12 23:50
professionalMarco Bertschi21-Oct-12 23:50 
GeneralRe: My vote of 1 Pin
Anuja Pawar Indore22-Oct-12 0:04
MemberAnuja Pawar Indore22-Oct-12 0:04 
GeneralMy vote of 1 Pin
Ingo21-Oct-12 22:17
MemberIngo21-Oct-12 22:17 
GeneralMy vote of 1 Pin
nagendrathecoder21-Oct-12 20:41
Membernagendrathecoder21-Oct-12 20:41 
GeneralMy vote of 1 Pin
Suresh Suthar21-Oct-12 20:12
professionalSuresh Suthar21-Oct-12 20:12 
GeneralMy vote of 1 Pin
saini arun19-Oct-12 20:02
Membersaini arun19-Oct-12 20:02 
GeneralMy vote of 1 Pin
RJOberg19-Oct-12 3:43
professionalRJOberg19-Oct-12 3:43 
GeneralRe: My vote of 1 Pin
Anuja Pawar Indore19-Oct-12 4:31
MemberAnuja Pawar Indore19-Oct-12 4:31 
GeneralReason for my vote of 4 It's nice Anuja Pin
kanjolia gopal22-Nov-11 19:26
Memberkanjolia gopal22-Nov-11 19:26 
GeneralRe: Thanks Kanjolia :) Pin
Anuja Pawar Indore22-Nov-11 19:32
MemberAnuja Pawar Indore22-Nov-11 19:32 
GeneralReason for my vote of 5 Nice ! Pin
Dilip Baboo13-Sep-11 13:12
MemberDilip Baboo13-Sep-11 13:12 
GeneralRe: Thanks Dilip Pin
Anuja Pawar Indore5-Oct-11 3:13
MemberAnuja Pawar Indore5-Oct-11 3:13 
GeneralReason for my vote of 1 Poor Pin
BrianBissell13-Sep-11 3:47
MemberBrianBissell13-Sep-11 3:47 

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

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