Last post Jul 24, 2017 05:24 AM by Cathy Zou
Jul 21, 2017 05:45 PM|aspfun|LINK
Ispostback is still confused me.
For example, I use query string to pass values from A.aspx to B.aspx like below code.
In B.aspx page load event, do I need add code "If Not IsPostBack Then...End If" ?
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim sCAMPUS As String = Request.QueryString("OrderName")
Dim sDATE1 As String = Request.QueryString("OrderDate")
Jul 21, 2017 05:58 PM|mgebhard|LINK
A query string is a query string regardless if the current request is a post back or not.
Post back is a convention in ASP Web Forms that is used to determine if the request is the initial load (GET) or the user submitted a form (POST). The convention is to initialize the page controls when the request is not a post back.
Jul 21, 2017 05:59 PM|A2H|LINK
do I need add code "If Not IsPostBack Then...End If" ?
its not mandatory that while reading values from querystring you need to put it inside IsPostback block.
Here is the difference
If you put it inside the block If(!IsPostback) then this code will execute only when the page is being rendered for the first time
If you put it outside then code to read querystring will execute every time page is responding to a postback like button click etc
Jul 21, 2017 06:07 PM|aspfun|LINK
As I understood, "Is postback" is only working with B.aspx page.
If there is a button in B.aspx, after clicking this button (will post back), does the value of query string will load again in B.aspx?
Jul 21, 2017 06:13 PM|A2H|LINK
If there is a button in B.aspx, after clicking this button (will post back), does the value of query string will load again in B.aspx
If you put the code to read querystring inside If Not IsPostBack Then , it wont load again
Jul 21, 2017 06:52 PM|aspfun|LINK
It is helpful.
Jul 22, 2017 03:59 AM|oned_gk|LINK
Simple example is you have a textbox in b page. Then you want to set the textbox text from querystrng at first time.
Jul 24, 2017 05:24 AM|Cathy Zou|LINK
If Not IsPostBack Then
//code in here
Code above means it works for first time form load. it does not work when button is clicked .
Then code in if statement will be execute only when the page is loading for the first time.
You could understand What is IsPostBack by referencing the following link: