Click here to Skip to main content
11,480,021 members (63,287 online)
Click here to Skip to main content

Tagged as

Calling a C# method using jQuery on the client side

, 2 Oct 2011 CPOL 8.8K 6
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: [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:

[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)

Share

About the Author

Anuja Pawar Indore
Program Manager 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 Pin
Marco Bertschi22-Oct-12 0:50
memberMarco Bertschi22-Oct-12 0:50 
Way too less informaation to be an article... Can you bring some meat up to this bone?
GeneralRe: My vote of 1 Pin
Anuja Pawar Indore22-Oct-12 1:04
memberAnuja Pawar Indore22-Oct-12 1:04 
GeneralMy vote of 1 Pin
ihoecken21-Oct-12 23:17
memberihoecken21-Oct-12 23:17 
GeneralMy vote of 1 Pin
nagendrathecoder21-Oct-12 21:41
membernagendrathecoder21-Oct-12 21:41 
GeneralMy vote of 1 Pin
Suresh Suthar21-Oct-12 21:12
memberSuresh Suthar21-Oct-12 21:12 
GeneralMy vote of 1 Pin
saini arun19-Oct-12 21:02
membersaini arun19-Oct-12 21:02 
GeneralMy vote of 1 Pin
RJOberg19-Oct-12 4:43
memberRJOberg19-Oct-12 4:43 
GeneralRe: My vote of 1 Pin
Anuja Pawar Indore19-Oct-12 5:31
memberAnuja Pawar Indore19-Oct-12 5:31 
GeneralReason for my vote of 4 It's nice Anuja Pin
kanjolia gopal22-Nov-11 20:26
memberkanjolia gopal22-Nov-11 20:26 
GeneralRe: Thanks Kanjolia :) Pin
Anuja Pawar Indore22-Nov-11 20:32
memberAnuja Pawar Indore22-Nov-11 20:32 
GeneralReason for my vote of 5 Nice ! Pin
Dilip Baboo13-Sep-11 14:12
memberDilip Baboo13-Sep-11 14:12 
GeneralRe: Thanks Dilip Pin
Anuja Pawar Indore5-Oct-11 4:13
memberAnuja Pawar Indore5-Oct-11 4:13 
GeneralReason for my vote of 1 Poor Pin
BrianBissell13-Sep-11 4:47
memberBrianBissell13-Sep-11 4: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 | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 2 Oct 2011
Article Copyright 2011 by Anuja Pawar Indore
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid