Solved

Page.Ispostback

Posted on 2006-07-17
9
403 Views
Last Modified: 2008-02-01
Morning all,

I have been a user of classic ASP for around 4 years and now I have ventured into .net.  I am doing OK but I am really struggling to understand what the page.ispostback is needed for?  Could someone give me a actual persons point of view because the text book answers I feel are too vague.

Thanks for your time,

Steve
0
Comment
Question by:stevemarsh99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17120853
Hi stevemarsh99,

It tells you if the page is loaded for the first time or if it has been reloaded( posted to), for example, from a form

Apresto
0
 
LVL 23

Expert Comment

by:apresto
ID: 17120857
so if you had this:

if (page.isPostBack )
{
   Response.write "It has been opened before"
}
else
{
   Response.write "This is the first time"
}

you will see what its form, try sticking a link or a form with a submit button on the page and see the difference in results
0
 

Author Comment

by:stevemarsh99
ID: 17120858
But why is that of any value?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 17120862
Hi stevemarsh99,

The principle is this, when you *first* navigate to a page then IsPostback is false because of course no action has occured except that navigation. In classic ASP you would normally POST a form to another page or even back to the same page for further actions. With asp.net, any submit, button click or other autopostback event (such as setting a dropdownlist's autopostback property to true) will post the form back to the same page. When this occurs IsPostback is now True. This can be useful when you need to perform certain population routines or other actions on the first hit to a page, subsequent postbacks would not need to populate dropdownlists etc (providing you have not turned off viewstate for the control or page)  so do not need to be executed. IsPostback can be used to adjust the processing of the code appropriately.

Tim Cottee
0
 
LVL 23

Expert Comment

by:apresto
ID: 17120863
if you wanted to find out if a form was submitted or not, or if the page had been loaded via link
0
 

Author Comment

by:stevemarsh99
ID: 17120895
Sorry I still can't seem to get my head round it...all I can work out is that if it is false then it is the first time the page has been rendered....great.  If it is true then it has been sumbitted by something...again ... great...I just cant see what the benifits are?
0
 
LVL 23

Expert Comment

by:apresto
ID: 17120903
Well.

Lets say when the form is submitted you want to execute some data activity as you are submitting form information

If the page is loaded for the first time, you dont want to talk top the database as you wont have any form info as the page has been loaded for the first time, therefore, no form info has been filled out yet

0
 

Author Comment

by:stevemarsh99
ID: 17120905
Tim I just read through it realllllly slowly and it does now make sense!!! Thank you very much for your help guys....

:D

Steve
0
 
LVL 3

Expert Comment

by:harshits
ID: 17120950
Hi stevemarsh99,

"isPostBack" is very useful and something you cannot do without when you are using the asp.net databound controls.

These controls maintain the viewstate (i.e. for eg a selected value in the dropdownlist) to maintain the state of the control between postback's.

Now when you are binding the control to the datasource in the page_load event of the page, you need to make sure that it is written inside the if(!page.isPostBack) block.

Cause otherwise the control will keep re-binding to the data source after every postback and thus loose the viewstate value (the value which your user selected before clicking the submit button).

Harshit Sheth

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question