Solved

Page.Ispostback

Posted on 2006-07-17
9
404 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

729 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