views:

2925

answers:

6

Hey,

Topic says it. Short version: I need a way to force a refresh of the page on First page-load only. Would be easy in asp.net, but I've no idea how to go about this in classic asp.

Longer version: I'm trying to update a rather large application, and one of its problems is that when you log in, it doesn't yet store the necessary information into sessions unless you click a few specific buttons OR refresh the page... which causes problems when the customer tries to navigate the pages.

I COULD track the sessions and set them manually, but I've failed in that for several hours now, so a forced refresh would be a lot easier. If only there's a way to detect the initial page-load so I won't cause a loop. Redirecting is out of the question as well, since the application has way too much code (all of which is practically uncommented and disorganized) for me to see how it actually builds all the verification checksums etc.

Edit: Thanks for replies and sorry for the late answer. Got some good ideas from you guys. :)

+3  A: 
  1. Check for a session cookie saying if it's the first load or not (true = has been loaded before, false = first load).

  2. a. If false, add a js that will reload the page to the response, and set the cookie to true
    b. If true, do nothing more. The page has been reloaded.

As long as the user keeps updating the session, this should make only the first load reload instantly.

EDIT: In response to a comment, the following is an example of a javascript that would cause the client page to reload. As far as I know, this is browser-independent:

<script type="text/javascript">window.reload();</script>


(I do admit that this seems somewhat like a hack, but it'll work. There might be some other way to make the page reload, without sending an extra javascript command, but I don't know of any in Classic ASP.)

Tomas Lycken
Hey, put this as the selected answer. I was sorta against using sessions at first as it places a workload on the server and this page is used by relatively many people at the same time. But this is beyond a doubt the easiest response. I'm a little afraid of scripts anyway since I'm not experienced enough to know which of them might not work on all browsers / settings, and the page needs to be as universally compatible as possible.
Zan
I believe <script type="text/javascript">window.reload()</script> will work in any browser - at least I haven't been able to find any information that suggests it won't.
Tomas Lycken
Ok, good to know. Thanks.
Zan
Edited my post to include it, too =)
Tomas Lycken
A: 

Reload the page with window.location="currentUrl?reloaded=true" in jQuery on document ready if say a query string param 'reloaded' == true.

Something like this:

<script type="text/javascript">
    $(document).ready(function() {
        if(!urlContainsReloadedIsTrue())
            window.location="currentUrl?reloaded=true";
        });
    });
</script>

You could build the urlContainsReloadedIsTrue() function with something like this.

cottsak
+1  A: 

Try out the following 3 steps:

  1. Add a hidden text box called firstload inside form tag and set its default value to "true"
  2. Add a javascript method to the page for execution during Window.Onload(). The javascript should check the value of firstload text box and if its "true", reload the page with appending a parameter to the querystring (?reloaded=true)
  3. In the server side code, check if querystring reloaded is true. If it is, then set value of firstload to "false".
Nahom Tijnam
+1  A: 

just add a new page to ur app, after login redirect that page.. i mean, when client complete the login job in login.asp. redirect the login2.asp.. set login2.asp content to a simple script..

<script type="text/javascript">window.location.href="home.asp"</script>
Tolgahan Albayrak
+1  A: 

Using VBScript.

You can reload the page by redirecting to itself and use a querystring variable:

<%
  Dim reload: reload = Request.Querystring("re") 
  If reload = "" Then
    Response.Redirect("samepage.asp?re=true")
  End If
%>

As an alternative you could set a session variable and check for that:

<%
  If Session("reload") = "" Then
    Session("reload") = "true"
    Response.Redirect("samepage.asp")
  End If
%>
Zaagmans
A: 

I had problems getting javascripts to work for some unknown reason, so in the end I used this simple codelet:

    If session("Firstupdate") <> "updated" Then
     Response.AddHeader "Refresh", "0" 
     session("Firstupdate") = "updated"
    Else
     Response.AddHeader "Refresh", "" 
     Session.Contents.Remove("Firstupdate")
    End If

That seems to be independent of any scripting and works well enough for my purposes. Ideally, removing the session means that while any additional refreshes will again force the page to go through 2 refreshes, at least the server isn't loaded with useless sessions when more customers pour in. I would rather have set the 'Session.Timeout' for the "Firstupdate" variable explicitly, but apparently timeout is universial for the entire session object and the variables it contains.

Again, sorry for late response and thanks for help.

Zan