Solved

Stop Function Executing on Page Refresh

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now