 |
|
|
I'm sure this is pretty easy to do but I'm javascript handicapped How do we go about adding a function to the alert box so that when they click the 'Ok' button, it will auto refresh their session state for them. This way the user won't have to know that they need to click on something that does a post back to restart their session timer?
Also, I don't suppose it's possible to add a real-time timer count down to that alert box is it so the user knows exactly how much time remains? This way if the user wasn't at the screen when the box first appeared but sat down soon after, they would know exactly how much time was really left? 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Robert,
If you want the page is refreshed after the user click 'OK' button, you just modify the javascript about like this: window.location.href = window.location.href (instead of window.location.href='login.aspx').
About the count-dount timer within the message box, you can search over the Internet to get the javascript code and modify it for your scenario. I think it is pretty easy
Live free, die well! http://www.sirvina.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks, I appreciate it
I'll give it a shot and see how it works.
I did notice one strange thing though. Not sure how or why, but I noticed that if I left that 3 minute count down window open and I waited an easy 5 minutes before pressing "OK", instead of it already timing out (since there was only 3 minutes left), my session wasn't timed out at all... I did a post back to check and sure enough, the post back worked... any idea why this would be? since it's client side script, i can't see how the server would've gotten a postback to reset the timer... (i had the web.config session timeout set at 4 minutes for testing purposes).
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Ok. It is really a strange. When you implement this, you already renew the session too
Live free, die well! http://www.sirvina.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Oh, well if that's the case than that explains why it didn't time out. cool, thanks for the help and the code! Now maybe the users will stop griping about wanting a warning of a pending session expiration... hehe
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, I implemented your code and it works fine but I got stuck with this problem: Because I am registering this function with setTimeOut of reminder session time, I get the confirm box eventhough I am working on it. Suppose I have a timeout of 20 min. I am registering this code with Session.Timeout delay. Even when I am working on the application, this function gets fired and I get the confirm box.
We are using sqlstate for storing sessions.
How can I avoid this confirm box to appear and make it appear when user has only 1 min left in the session?
Thanks in advance, Chaggu.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
You are working, but maybe you do not make any postbacks to server, so it still show message to confirm by the time session timeout. During your session, if you make some postbacks, the message must NOT appear (because the time to remind has been reset!).
Live free, die well! http://www.sirvina.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks for your quick reply.
The problem is I have an application with single page and multiple tabs. I put this script register block in Page_load of that page. It doesnt get called even if a new tab is created or a postback happens in the tab.
Can you please suggest me something else, I would really appreciate?
Thanks, Chaggu.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, I think your tab control is not in the update panel. If you do not use update panel, you should try to replace ScriptManager.RegisterClientScriptBlock(...) with Page.RegisterClientScriptBlock(...) method
Live free, die well! http://www.sirvina.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I am using an Alert box instead of Confirm box and it works for my scenario. Thanks for replying. Thanks, Chaggu.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Thanks for this article.
i just want to ask what could be wrong with my implementation because nothing is happening when i did something inside the update panel. the injected javascript code seem like its not taking in effect. I hope you can help me on this.
Thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Could you post something about your code? Did you try to register javascript with ScriptManager.RegisterClientScriptBlock(...) method instead of Page.RegisterClientScriptBlock(...)?
Live free, die well!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
i registered the javascript by user ScriptManager.RegisterClientScriptBlock
if i run the application and do nothing, after the set timeout, it works fine, it redirects to the page it set. but when i did something on the update panel, say, i populated a gridview, and do nothing after that, wait for the set timeout, nothing happened, as if the javascript code didn't took in effect. please help me on this.
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Did you add the function generate javascript to PageLoad (without inside !Page.IsPostBack) yet? After gridview changed, it would call this function to re-generate again the javascript snippet. And it should work fine.
Live free, die well! http://www.sirvina.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, I am using rad ajax now i am having the same problem i.e when i do a operation in the grid and leave the operation the page does nort redirect on session timeout.I have take care of adding generate javascript functon to PageLoad?please help
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
If you don't use alert in doReminder()-function, but a hidden html-control (like span) you can include a link in the control to refresh the session (like do a postback, form.submit or load something).
Or if you have a javascript in your input-fields: After doReminder()-time has passed the input-field javascript could set a flag that user have done some input near session expire time. Then you know that user is near and you can refresh the session just before it expires. A kinda like gmail saving the new message to draft.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
I was looking for something like this just a few days ago. Now I have a good example.
Many thanks.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
I think the easier solution is to use the META tag for refresh and set the url to go to a TimeOut.aspx page, I use this all over one of our portal websites, and it works great.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
If you don't use Ajax UpdatePanel in the page then the META tag refresh works great. But if the page contains UpdatePanel, it gets a problem. When the user made the postback, the META tag content does not refresh to get new time out for session (because META tag isn't inside any updatepanel). So it does not work correctly!
Live free, die well!
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
This situation is easily resolved by using one of those approaches: using Inheritance in pages that needs valid Session:
public abstract class SessionPage : Page { protected override void OnLoad(EventArgs e) { if(Session["SomeSessionIdentifier"] == null) { Response.Redirect("~/login.aspx");
} } } public class MyPersonalPage : SessionPage { //This page only executes to the end if the session is valid }
Or by using Forms Authentication. Id never used this technique, if someone have more details, please reply some examples to enrich the contents of the article. And sorry my english 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi tkrafael_net, 1. About your inheritance method in order to valid session: Remember that, sometimes we ourself set Session["SessionName1"] == null although the current session state still alive. In this case, Session is null but the user's session state has not ended yet. So that, assume that we have 2 session variables, and we set session1=null, session2='abc' then if you check session is null then redirect to Login page, that's such not correct, because session2 still remain its value. Right? 
2. Forms Authentication sometimes does not work correctly in some cases, I experienced...
Live free, die well!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
The only major issue with trying the redirect approach (which many have tried) is that unless it's a "Full Page" postback (rather than an Ajax Callback), you are not allowed to execute a Response.Redirect.
This code will throw an exception if you are doing an Ajax callback which defeats the point of the article.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Its possible that during an ajax postback, to register client scripts? If so, is possible redirect via client scripts... Is in that way i use
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |