Reputation: 317
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. :)
Upvotes: 4
Views: 38594
Reputation: 317
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.
Upvotes: 1
Reputation: 60584
Check for a session cookie saying if it's the first load or not (true
= has been loaded before, false
= first load).
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.)
Upvotes: 6
Reputation: 5302
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
%>
Upvotes: 2
Reputation: 3206
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>
Upvotes: 2
Reputation: 4854
Try out the following 3 steps:
Upvotes: 2
Reputation: 11535
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.
Upvotes: 1