Solved

Stop Function Executing on Page Refresh

Posted on 2008-10-01
5
518 Views
Last Modified: 2012-05-05
How can I make a function only execute on the first page load and not when a person/user clicks the refresh button?
I have tried the following but it does not work.

I also have hyperlinks in the page which also cause the fuction to execute becuase their navigateURL is the same page (they are used to sort the DB results.)

Thanks
If Not Page.IsPostBack Then
                    loadDBHotels()
else
 findMatch()
 
                End If

Open in new window

0
Comment
Question by:footballencounters
[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
5 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 22613881
Check What you are getting in Response.Write(Request.UrlReferrer.AbsoluteUri) , then in page load

check that if its coming form same page ( Refresh did the same ) then do not excute that function like below


  If (Request.UrlReferrer.AbsoluteUri <> "http://localhost:3160/CMA/WebForm1.aspx") Then
            loadDBHotels()
        End If
0
 
LVL 20

Expert Comment

by:informaniac
ID: 22613955
Pass a querystring when u r setting the navigateUrl

Reload = 1 in the navigateurl....


If Request.Querystring("Reload") Is Nothing OrElse Request.Querystring("Reload").ToString().Equals("0") Then
    
    loadDBHotels()
End If

Open in new window

0
 

Author Comment

by:footballencounters
ID: 22614296
informaniac:
Your suggestion works well from links within the page but does not solve the problem of a refresh.

pratima_mcs:
Is there any way of just checking the last part of the URL (i.e. the page name only) rather than the full absolute URL as this becomes a problem when moving the site to different base domains.

Thanks both for your assitance
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 22614299
Use a session variable. When loaded first time, add this variable to the session and then check for its existence when refreshing. For example

If Not Page.IsPostBack Then
   if not session("DetailsPageLoaded") Then
      loadDBHotels()
   End If
else
 findMatch()
 Session("DetailPageLoaded")=True
End If
0
 

Author Closing Comment

by:footballencounters
ID: 31501936
Thanks - that was the most logical solution.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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