Solved

Page.Ispostback

Posted on 2006-07-17
9
398 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
9 Comments
 
LVL 23

Expert Comment

by:apresto
Comment Utility
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
Comment Utility
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
Comment Utility
But why is that of any value?
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 23

Expert Comment

by:apresto
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now