Saturday, 16 June 2012


Autopostback is the mechanism, by which the page will be posted
back to the server automatically based on some events in the web controls. In some of the web controls, the property called auto post back, which if set to true, will send the request to the server when an event happens in the control.

For e.g 


  <td align="center" colspan="3">
                                                <asp:TextBox ID="txtID" runat="server" ontextchanged="txtID_TextChanged" AutoPostBack="true"></asp:TextBox>

<td align="center" colspan="3">
                                                <asp:TextBox ID="txtDesc" runat="server"></asp:TextBox>

C# : 

        protected void txtID_TextChanged(object sender, EventArgs e)
            BusinessLayer.Test test = new BusinessLayer.Test();
            txtDesc.Text = test.getDesc(txtID.Text); 

 Java script  

method with name __doPostBack (eventtarget, eventargument)
b. Two Hidden variables with name __EVENTTARGET and __EVENTARGUMENT
c. OnChange JavaScript event to the control



When we discuss about autopostback, we should have an understanding of the IsPostBack property of Page class. IsPostBack property is used by the Page to determine whether the page is posted back from the client. If IsPostBack property is false, then the page is loading for the first time, and if false, then the request is because of some event generated by web controls.
IsPostBack is used when we want to load some information when the page loads, for e.g. if we want to load some information from the database and show in the data grid in a page for the first time, then we can load and bind the grid in the page_load when IsPostBack property is false.

try it.. 
Now it send text back to server because AutoPostBack =true 

So ... If it false can check ,.wt happens...
Happy Coding

No comments:

Post a Comment