Solved

How to avoid page realod using Page.IsPostBack?

Posted on 2008-10-03
1
386 Views
Last Modified: 2012-05-05
I have a confirmation page that when it loads up the first time it executes some code. What I'm trying to prevent is when you refresh that page it should not execute the code anymore and hence should do something else e.g. redirect to another page.

The code is as follows:

If Page.IsPostBack = False Then

//code to be executed when loaded the first time

Else

//code to redirect to another page

End If

The problem I'm having is when you initially get to the page (for the first time) it executes the code in the if condition, but when I refresh the page it again executes the code in the if statement, where as it should execute the code in the else statement.

Can anyone see where I'm going wrong?

Thanks
0
Comment
Question by:Gary2Seven
[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
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 22632543
the "postback" is ONLY true when you have a postback, ie via a button.
if you use F5 (in IE) to refresh the page, it will not be a postback.

to solve that, you have to set a session variable, for example, on the IsPostBack = false, and check on that one.
If Page.IsPostBack = False Then
  If Session("page_loaded") = "YES" Then
    //code to redirect to another page
    // -> in that other page, the session "page_loaded" needs to be cleared again!!
  Else
    //code to be executed when loaded the first time
   
    Session("page_loaded") = "YES"
  End If
Else
 //code to redirect to another page
End If

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
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 …

691 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