Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Page.Ispostback

Posted on 2006-07-17
9
Medium Priority
?
407 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 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

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!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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