Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
suppose my page is ex.aspx
in the aspx.cs file how will the following code work??

if(!exPostback)
{
do something
}

does the control enter the loop if the page is loaded on browser for the first time or again and again????


and what does this mean??
return (ViewState["exPostback"] != null);


thanks in advance!!!!
Posted

You need to look at the page event lifecycle: http://msdn.microsoft.com/en-us/library/ms178472.aspx[^] - the Load event for teh page is called every time you past back, becuas eteh server does not maintin the page status after the HMTL has been sent to teh client: it is thrown away.

So, when you press a button on the page, a postback occurs, the page is loaded, the Load event occurs and then the button Click event.
In you Load event, you can use Page.IsPostBack to check if this is the first time, or in response to an action at the client end - so you don't overwrite what the user typed when he clicked the button! I'm guessing that your code is typed wrong in the example above...
 
Share this answer
 
Comments
Nandakishore G N 11-Mar-14 7:37am    
you are right.My 5..
Is Postback is normally used on page _load event to detect if the page is getting generated due to postback requested by a control on the page or if the page is getting loaded for the first time.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900