?
Solved

Stop Function Executing on Page Refresh

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
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 …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

801 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