What is a postback?

Postback

Postback Problem Overview


I'm making my way into web development and have seen the word postback thrown around. Coming from a non-web based background, what does a new web developer have to know about postbacks? (i.e. what are they and when do they arise?)

Any more information you'd like to share to help a newbie in the web world be aware of postbacks would be most greatly appreciated.

Postback Solutions


Solution 1 - Postback

The following is aimed at beginners to ASP.Net...

When does it happen?

A postback originates from the client browser. Usually one of the controls on the page will be manipulated by the user (a button clicked or dropdown changed, etc), and this control will initiate a postback. The state of this control, plus all other controls on the page,(known as the View State) is Posted Back to the web server.

What happens?

Most commonly the postback causes the web server to create an instance of the code behind class of the page that initiated the postback. This page object is then executed within the normal page lifecycle with a slight difference (see below). If you do not redirect the user specifically to another page somewhere during the page lifecycle, the final result of the postback will be the same page displayed to the user again, and then another postback could happen, and so on.

Why does it happen?

The web application is running on the web server. In order to process the user’s response, cause the application state to change, or move to a different page, you need to get some code to execute on the web server. The only way to achieve this is to collect up all the information that the user is currently working on and send it all back to the server.

Some things for a beginner to note are...

  • The state of the controls on the posting back page are available within the context. This will allow you to manipulate the page controls or redirect to another page based on the information there.
  • Controls on a web form have events, and therefore event handlers, just like any other controls. The initialisation part of the page lifecycle will execute before the event handler of the control that caused the post back. Therefore the code in the page’s Init and Load event handler will execute before the code in the event handler for the button that the user clicked.
  • The value of the “Page.IsPostBack” property will be set to “true” when the page is executing after a postback, and “false” otherwise.
  • Technologies like Ajax and MVC have changed the way postbacks work.

Solution 2 - Postback

From wikipedia:

> A Postback is an action taken by an > interactive webpage, when the entire > page and its contents are sent to the > server for processing some information > and then, the server posts the same > page back to the browser.

Solution 3 - Postback

Expanding on the definitions given, the most important thing you need to know as a web-developer is that NO STATE IS SAVED between postbacks. There are ways to retain state, such as the Session or Viewstate collections in ASP.NET, but as a rule of thumb write your programs where you can recreate your state on every postback.

This is probably the biggest difference between desktop and web-based application programming, and took me months to learn to the point where I was instinctively writing this way.

Solution 4 - Postback

Postback happens when a webpage posts its data back to the same script/dll/whatever that generated the page in the first place.

Example in C# (asp.net)

...

if (!IsPostback)
   // generate form
else
   process submitted data;

Solution 5 - Postback

Web developement generally involves html pages that hold forms (<form> tags). Forms post to URLs. You can set a given form to post to any url you want to. A postback is when a form posts back to it's own page/url.

The term has special significance for ASP.Net WebForms developers, because it is the primary mechanism driving a lot of the behavior for a page — specifically 'event handling'. ASP.Net WebForms pages have exactly one server form which nearly always posts back to itself, and these postbacks trigger execution on the server of something called the Page Lifecycle.

Solution 6 - Postback

The term is also used in web application development when interacting with 3rd party web-service APIs

Many APIs require both an interactive and non-interactive integration. Typically the interactive part is done using redirects (site 1 redirects a user to site 2, where they sign in, and are redirected back). The non-interactive part is done using a 'postback', or an HTTP POST from site 2's servers to site 1's servers.

Solution 7 - Postback

When a script generates an html form and that form's action http POSTs back to the same form.

Solution 8 - Postback

Postback is essentially when a form is submitted to the same page or script (.php .asp etc) as you are currently on to proccesses the data rather than sending you to a new page.

An example could be a page on a forum (viewpage.php), where you submit a comment and it is submitted to the same page (viewpage.php) and you would then see it with the new content added.

See: http://en.wikipedia.org/wiki/Postback

Solution 9 - Postback

Postback refers to HTML forms. An HTML form has 2 methods: GET and POST. These methods determine how data is sent from the client via the form, to the server. A Postback is the action of POSTing back to the submitting page. In essence, it forms a complete circuit from the client, to the server, and back again.

Solution 10 - Postback

A post back is anything that cause the page from the client's web browser to be pushed back to the server.

There's alot of info out there, search google for postbacks.

Most of the time, any ASP control will cause a post back (button/link click) but some don't unless you tell them to (checkbox/combobox)

Solution 11 - Postback

Yet the question is answered accurately above, but just want to share my knowledge . Postback is basically a property that we can use while doing some tasks that need us to manage the state of the page, that is either we have fired some event for e.g. a button click or if we have refreshed our page. When our page loads for the very first time , that is if we have refreshed our page, at that time postback-property is false, and after that it becomes true.

if(!ispostback)
{
 // do some task here
}
else
{
 //do another task here
}

http://happycodng.blogspot.in/2013/09/concept-of-postback-in.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionScott SaadView Question on Stackoverflow
Solution 1 - PostbackAndy McCluggageView Answer on Stackoverflow
Solution 2 - PostbackGalwegianView Answer on Stackoverflow
Solution 3 - PostbackRB.View Answer on Stackoverflow
Solution 4 - PostbackChris CudmoreView Answer on Stackoverflow
Solution 5 - PostbackJoel CoehoornView Answer on Stackoverflow
Solution 6 - PostbackHemantView Answer on Stackoverflow
Solution 7 - PostbackmspmspView Answer on Stackoverflow
Solution 8 - PostbackMorphioView Answer on Stackoverflow
Solution 9 - Postbacksteve_cView Answer on Stackoverflow
Solution 10 - PostbackMilesView Answer on Stackoverflow
Solution 11 - Postbackuser3114934View Answer on Stackoverflow