Resources » Code Snippets » ASP.NET WebForms

How to use IsPostBack property in ASP.NET pages to determine if the page is posted back


Posted Date: 02-Apr-2004  Last Updated:   Category: ASP.NET WebForms    
Author: Member Level: Gold    Points: 5


This article demonstrates how you can use the Page.IsPostback proeprty to determine of the page is submitted or it is first time loading.



In ASP.Net, the Page Load is event is fired every time a page is loaded. This is true even if the page is loaded as part of a submit button click. You may need to identify if the page load event is called as part of a page submit or if it is a fresh page rendering. Because, in case of page submit, you may want to skip several task like populating the data again etc.

The IsPostBack property can be used to determine if the page is submitted to itself. When a form is posted (submitted) back to the same page that contains it, it's called a post back. ASP.NET provides a property called IsPostBack that is TRUE when the page is being loaded as a result of a post back, and is FALSE otherwise.

We can check the value of this property and based on the value, we can populate the controls in the page. If the property is TRUE, that means it is a postback (submit) and no need to populate all the values again.

Sample

Sub Page_Load
IF Not IsPostBack THEN
' Need to do load the grid only if it is first time load.
grdtest.DataSource = Session("dS")
grdtest.DataBind()
END IF
End Sub


Did you like this resource? Share it with your friends and show your love!

Responses to "How to use IsPostBack property in ASP.NET pages to determine if the page is posted back "
Author: Ahmad M. Alkilani    27 Apr 2004Member Level: Bronze   Points : 0
Thank you for writting this article. You explained the topic well.


Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India