Last post Jul 28, 2010 09:18 AM by sarathi125
Jul 28, 2010 07:01 AM|sab.ahamed|LINK
i need full detail of postback.. i need extract meaning ..and type of postback...
Jul 28, 2010 09:05 AM|vdogra77|LINK
Suggest you to go through any of the article for understanding ASP.Net page life cycle, and you will understand what Postback is and where does it falls under the entire life cycle. In the process you will also learn what goes where for you to design your
Jul 28, 2010 09:16 AM|karthicks|LINK
PostBack - when an asp.net web form is submitted to the server using some event such as TextBox textchanged event, dropdown selectedindexchaged or gridview events, Button click evnt is called as
Jul 28, 2010 09:18 AM|sarathi125|LINK
You put a DropDownList or a ListBox (or just about any ASP.Net control which has multiple items assigned to it) on your web page (inside a form, naturally). Then, at some point, you either populate the list items manually, or bind it to a database table.
However, you do it, you get a list of items from which, at some point, the end user can make a choice. Based on that choice, the end user gets more data in return. Most of the basic item population of these controls is done during the initial loading of the
page (Page_Load event). That way, the list items are available for choosing once the page is finished loading.
Let's say, then, you also put a button on the page. That way, the end user can choose an item in the list, click the button and get the extended data, based on the selection made. The button's click event would then take the item which was selected and use
it in a click event that could then, possibly connect to a database and use the selected item's data to filter a query against a database.
"Of course", you say - "Simple", you say - "No Problem!", you say - even "Why are you bothering me with this drivel?" This is where it all boils down to the mystery for which this tutorial was created. Here it is - your DropDownList was populated with the
last names of people at your company. You create a sub procedure for the onclick event of the button to connect to the database and give the end user back all the available data in the table, based on that last name. The SQL statement goes something like this:
SQL = "Select * from Employees where lastname = '" & DropDownList.SelectedItem.Text & "'"
However, when you do this, you either get an error, or you get absolutely no results back from the query. You're sure the query is correct - but you can't figure out why this isn't returning any records.
That's because you didn't surround the data population of your control with the basic statement this tutorial is all about:
If not Page.IsPostback then
What's happening is that your page is re-loading the data into your server control - it's not responding in any way, to the click event from the button click. First of all, you would never need the server control to re-populate EVERY time the page loaded.
That would be terribly inefficient and as you have seen here - it makes making a choice from the control pretty much unuseable.
As I said at the beginning, there are a couple of ways to populate the data items of a server control (DropDownList, ListBox, RadioButtonList, CheckBoxList, etc) - manually and binding the results from a database query to it. It doesn't matter how you populate
the data. What DOES matter is that you include the population of the control within the boundaries of this If/Then Statement.
Two things will happen then. The first thing that will happen, is that, on each subsequent loading of the page, the control doesn't go through the redundant action of re-loading the control. It loads it only once, at the initial page load. Once the page
is loaded, the click event from the button (or however you post back) is considered to be a postback. Yes, the page gets reloaded, but, by surrounding your data population with this statement, the page knows that the initial data loading was already done,
so it doesn't happen any more, and it gets maintained throughout any subsequent post back. The second, and most rewarding thing that happens is that the selection which was made by the end user is maintained throughout the post back. This is the pay-off -
by doing it with the If/Then Page.IsPostBack statement, your selection carries through to your query and the query returns the results you wanted in the first place.