How to Implement get and post methods in asp.net web forms using asp.net C#
Please Help Me !..................
How to Implement get and post methods in asp.net web forms using asp.net C#
Please Help Me !..................
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 17, 2023, 3:13 AM EDT
1. Create a new Web Forms application in Visual Studio.
2. Add a new Web Form to the project.
3. Add server controls to the Web Form to accept user input.
4. In the code-behind file of the Web Form, add event handlers for the GET and POST methods.
5. In the GET event handler, retrieve data from the server and populate the server controls with the data.
6. In the POST event handler, process user input and perform any necessary actions on the server.
TarunRank #6,374 · 268 reputationPosted Mar 17, 2023, 12:51 AM EDT
How To Implement the Restful Web Services Get and Post Methods In asp.net and its hit the postman
Please Help Fast.....!
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 17, 2023, 3:13 AM EDT
public partial class MyWebForm : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Perform actions on initial GET request } } protected void btnSubmit_Click(object sender, EventArgs e) { // Process user input and perform necessary actions on the server } }The Page_Load event handler is called when the Web Form is first loaded on a GET request. The IsPostBack property is used to determine whether the request is a POSTback (i.e., the result of a form submission) or an initial GET request.
The btnSubmit_Click event handler is called when the user clicks the Submit button on the form. This method is used to process the user input and perform any necessary actions on the server.
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 19, 2023, 8:23 PM EDT
1. Create a new ASP.NET Web Application project in Visual Studio.
2. Add a new Web API Controller class to the project.
3. In the Controller class, create methods for the GET and POST operations.
[HttpGet] public IHttpActionResult GetData() { // Get data from database or other data source var data = new List { "Data 1", "Data 2", "Data 3" }; // Return the data as JSON return Json(data); } [HttpPost] public IHttpActionResult AddData([FromBody]string newData) { // Add the new data to the database or other data source // ... // Return a success message return Ok("Data added successfully"); }4. Build and run the project.
5. Test the GET and POST methods using Postman or any other REST client. To test the GET method, send a GET request to the URL of the controller action (e.g., http://localhost/api/Controller/GetData). To test the POST method, send a POST request to the URL of the controller action with the new data as the request body (e.g., http://localhost/api/Controller/AddData).
6. Verify that the response from the server is as expected.
TarunRank #6,374 · 268 reputationPosted Mar 20, 2023, 3:52 AM EDT
dear @Tuhin paul brother
i was told that i should not take the controller i have to take normal class and it should work as a controller this is my requirement pls help me find out when i hit postman it checks the class
Sachin SinghRank #66 · 26.2K reputationPosted Mar 20, 2023, 4:04 AM EDT
In web forms we create web methods that serves like API service and could be consume using ajax calls.
function ShowCurrentTime() { $.ajax({ type: "POST", url: "CS.aspx/GetCurrentTime", data: '{name: "' + $("#")[0].value + '" }', contentType: "application/json; charset=utf-8", dataType: "json", success: OnSuccess, failure: function(response) { alert(response.d); } }); } function OnSuccess(response) { alert(response.d); }[System.Web.Services.WebMethod] public static string GetCurrentTime(string name) { return "Hello " + name + Environment.NewLine + "The Current Time is: " + DateTime.Now.ToString(); }Satyaprakash SamantarayRank #101 · 21.1K reputationPosted Dec 27, 2023, 4:55 AM EST
for web api get method using asp.net web form >> https://shorturl.at/ijnv8
Anandu G NathRank #681 · 3.5K reputationPosted Dec 27, 2023, 4:07 AM EST
Refer Below
https://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/jquery-ajax-get-and-post-calls-to-controllers-method-in-mvc/
Jignesh KumarRank #91 · 22.9K reputationPosted Mar 17, 2023, 3:27 AM EDT
Hello Tarun,
Please refer this one,
https://www.c-sharpcorner.com/article/calling-web-api-using-httpclient/
https://www.aspsnippets.com/Articles/Call-Consume-Web-API-in-Code-Behind-in-ASPNet-using-C.aspx#:~:text=In%20order%20to%20add%20a,suitable%20name%20and%20click%20OK.