Solved

Stop Function Executing on Page Refresh

Posted on 2008-10-01
5
519 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

728 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