Impact of Gen-AI on IT Jobs - Growth Mindset Show
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
iOS
Java
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
9
Reply
Can we call C# code behind using jQuery?
Nitin Choudhary
10y
2.6k
0
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
Yes we can call C# Web method from Jquery. Like - $.ajax({type: "POST",url: "Default.aspx/WebMethodName",data: '{}',contentType: "application/json",dataType: "json",success: function (data) {},error: function (x, e) {alert("The call to the server side failed. " + x.responseText);}})
Md. Raskinur Rashid
10y
3
YES
Amaya Pani
10y
0
Yes,But it having some prerequisiteC# method mark as webmethod. Webmethod should be public. Webmethod also be static.[webmethod] Public static
YourMethodName( parameter... ) { } for your knowledge this method call in two ways one way is Using PageMethods.YourMethodName( Parameter, OnSuccess ,OnFailure ). For this way you required to add
on page.Second way using Jquery Ajax.Sorry for spelling mistake.
Vaibhav Salwe
10y
0
$.ajax({ type: "POST", url: "Default.aspx/WebMethodName", data: '{}', contentType: "application/json", dataType: "json", success: function (data) {}, error: function (x, e) { alert("The call to the server side failed. " + x.responseText); } })and your method should be [webmethod] public static string WebMethodName() { return "success";}
Shuvojit Halder
10y
0
We can call a Web method using ScriptManager as well.
& In javascript, PageMethods.
(parameters, onSuccess, onFail);
Rasmita Dash
10y
0
Is it only work with web method?
Rahul Bansal
10y
0
use Jquery.Ajax$.ajax({url: "test.html",context: document.body }).done(function() {$( this ).addClass( "done" ); });
Abrar Ahmad Ansari
10y
0
Yes, we can call C# web method from Jquery for Exmple JavaScript code$.ajax({type: "POST",url: "CS.aspx/GetName",data: '{name: abcd }',contentType: "application/json; charset=utf-8",dataType: "json",success: OnSuccess,failure: function(response) {alert(response.d);}});}function OnSuccess(response) {alert(response.d);}C#[System.Web.Services.WebMethod]public static string GetName(string name){return "Hello " + name ; }
Navin Kumar
10y
0
Yes, we can call C# code from jQuery as it supports .net application
Nitin Choudhary
10y
0
What are the basic selectors in jQuery?
What is the use jQuery.data method?
Message