Aleksei Chepovoi
Aleksei Chepovoi

Reputation: 3955

What is a postpback request in asp.net?

I'm new to web programming, recently started to learn asp.net. Could anyone explain to me what is a postback request and how it defers from simple (if I can call it so) request?

Upvotes: 1

Views: 374

Answers (4)

syed mohsin
syed mohsin

Reputation: 2938

PostBack is the name given to the process of submitting an ASP.NET page to the server for processing. PostBack is done if certain credentials of the page are to be checked against a database (such as verification of username and password) or doing some calculation.
This is something that a client machine is not able to accomplish and thus these details have to be ‘posted back’ to the server.
Postback occurs usually when you click a button, radiobutton, checkbox or any other control(if you specify OnClick event in the markup). Many other event also call postback if specified in the markup.

Note: When a postback goes to server it also process page_Load event of the current page.

Upvotes: 2

Keith Nicholas
Keith Nicholas

Reputation: 44288

Microsoft tried to make web programming a bit like windows programming... it came up with webforms. When you first get a page from asp.net you do a GET, and you get a "webform" which is a webpage with buttons, text boxes, combo boxes, much like a windows dialog.

Now, microsofts framework has a bit of magic that you means you can configure a change ( like a button click, or change of a combobox ) to do a postback. That means the browser will POST back the page with the changes, it then translates these into events, like text changing, or button clicking, or combobox changing. Which you can handle, then it resends the changed page back to the browser.

So basically postbacks are triggered points where you can handle events on the server when using webforms. This is not exactly how other web frameworks work.

Upvotes: 3

mcalex
mcalex

Reputation: 6778

Simple request is 'give me page so-and-so'.

Postback request is 'give me page so-and-so (which I am already on) but when you post it back, change these data accordingly (which will be the result of the user selecting a combo box, or checking a radio button or whatever).

When you're coding asp.net you put all the stuff that happens in the first visit to the page in the page_load surrounded by a

if (!postback)
{
}

This ensures that code that should load when the user first visits the page doesn't happen when the user has set the above-mentioned options

Upvotes: 2

Darin Dimitrov
Darin Dimitrov

Reputation: 1038750

In ASP.NET, there's this thing called PostBack. In a classic ASP.NET WebForm you could have only a single <form> element with method="post" inside the entire page. And everytime you click on a button that's inside this form or perform some action, ASP.NET will POST to the same WebForm. Thus the name PostBack. So basically you will use a GET request to render the webForm for the first time and from now on everything you do on this form will result in a POST request to itself.

In a normal web application, you could have multiple <form> elements inside the HTML. Each form could post to different endpoints, some using GET, other using POST requests.

Upvotes: 1

Related Questions