[Solved] Please help me understand AutoPostBack property of an ASP.NET control

I’m learning about ASP.NET, mainly by following through a book, but also making an effort to actually do things along the way. But, I came across an explanation about list controls which I don’t understand. This is what it says:

“[in the context of the Smart Tasks panel]…the last option sets the AutoPostBack property of the control. With this option checked, the control will submit the page it’s contained in back to the server as soon as the user chooses a new item from the list

Can you explain this statement for me? Thanks in advance for your help.

Solution #1:

For normal client controls (such as a list control with AutoPostBack set to false), when a user chooses an item in the list, the browser does not communicate with the server. There’s no network traffic and no delay for your user before they see the results of the choice, but there’s also no opportunity to do anything in your server code, like calculate dependent values. If you want to do anything to the screen in response to the choice, you have to use a client-side script.

When AutoPostBack is set to true, selecting an item in the list sends a message to the server (via an HTTP POST). ASP.NET then executes whatever code you have attached to the list’s changed event, rebuilds the page, and sends the revised page to the client.

Respondent: Jeff Sternal

Solution #2:

If you set AutoPostBack="true" on a control, when it’s value changes, it will automatically postback to the server.

For example if you wanted a dropdown that when changed displayed different data in a table below or something, you might want to postback get the new value so your page could refresh the data.

This is opposed to style of the dropdown and a button beside it you click to postback, so instead of change value, click the button, you can just change the value with AutoPostBack="true".

Respondent: Nick Craver

Solution #3:

A ListBox has a SelectedIndexChanged event that you can handle to detect when the selected item in a ListBox has changed. You’d configure it like this:

<asp:ListBox ID="ListBox1" runat="server" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"/>

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    // Do something         

With AutoPostBack="false" (the default), that event handler doesn’t actually happen on the server in “real time”. The user has to perform an unrelated action to submit (POST) the form, such as clicking a button, to make that event fire on the server.

If you want to take “real time” action on that event, you set AutoPostBack="true" which makes the form automatically submit every time the selected item is changed.

The benefit – you get “real time” notification of events. The drawback – the page talks a lot more to the server, so each click costs bandwidth and causes client “lag”.

Further reading: http://www.dotnetspider.com/resources/189-AutoPostBack-What-How-works.aspx

Respondent: Greg

Solution #4:

When a user selects a ListItem (or whatever the collection item is), the page should automatically submit the web form to the server with a POST event.

here’s the wikipedia page on HTTP POST events

Respondent: David Fox

Solution #5:

The responsibility of an asp.net control contained in a Page is to render a part of the html that the user will end up seeing in his browser. Some controls support the AutoPostBack property. What it does is that it makes the control emit some extra javascript that will submit the form whenever the value of that control is changed, so that you can react to this on the server side.

Solution #6:

  • Basically AutoPostBack is used so that whenever there is some change in the controls text or anyother change in the controls property, the page is submitted to the server.
  • Posting the page means, the page is submitted to the server. Suppose i use a textbox and i make its AutoPostBack = “true”, now i write some text into it and click outside the textbox, then the page will refresh.
  • This refresh indicates that your value which you entered into the textbox has been submitted to the server.
  • The postback is handled by ASP.NET server. AutoPostBack will automatically post back your page to the server.
  • Add an event Handler. This will give you a better picture.
    In your case of DropDownList: Add an eventhandler: double click the DropDownList, it will route you to an eventhandler:
  • Write something in that event handler let us say : Response.Write(“message”);
  • The page will refresh and you will see your message, this means the page was posted to the server and the server has executed your event handler and displayed you the message.

I hope this was usefull

Respondent: Rahul

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.