[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Stop Function Executing on Page Refresh

Posted on 2008-10-01
5
Medium Priority
?
527 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

656 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