User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 391,594 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,669 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser:
Views: 13981 | Replies: 2
Reply
Join Date: Sep 2005
Posts: 7
Reputation: sandy2005 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sandy2005 sandy2005 is offline Offline
Newbie Poster

Redirect to loginpage on Session timeout

  #1  
Sep 30th, 2005
Hi

I have found the following code for Redirecting the user to loginpage on Session timeout :

///////////
Protected WithEvents body As System.Web.UI.HtmlControls.HtmlGenericControl

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 5000 & ");")

Response.Write("Wait for session to timeout..")

End Sub

////////

I am trying to use the same code in C#, but I get errors in the line:

body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 5000 & ");")

The errors I get are as below and all are in the same above line:

) expected
; expected
; expected
Invalid Expression Term')'
; expected

Please somebody let me know how to rectify the error.

Thanks
Sandy
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2005
Location: Mountain View, CA
Posts: 47
Reputation: kedar_challa is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
kedar_challa's Avatar
kedar_challa kedar_challa is offline Offline
Light Poster

Re: Redirect to loginpage on Session timeout

  #2  
Nov 9th, 2005
Originally Posted by sandy2005
Hi

I have found the following code for Redirecting the user to loginpage on Session timeout :

///////////
Protected WithEvents body As System.Web.UI.HtmlControls.HtmlGenericControl

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 5000 & ");")

Response.Write("Wait for session to timeout..")

End Sub

////////

I am trying to use the same code in C#, but I get errors in the line:

body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 5000 & ");")

The errors I get are as below and all are in the same above line:

) expected
; expected
; expected
Invalid Expression Term')'
; expected

Please somebody let me know how to rectify the error.

Thanks
Sandy

Hi Sandy,
try the following code.
[HTML]
string str = "window.setTimeout(window.location.href='login.aspx'," & "(Session.Timeout * 60 * 1000) + 5000);";
body.Attributes.Add("onLoad",str )

[/HTML]
Thanks,
Kedar
Reply With Quote  
Join Date: Feb 2007
Posts: 1
Reputation: mvalid is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mvalid mvalid is offline Offline
Newbie Poster

Re: Redirect to loginpage on Session timeout

  #3  
Feb 16th, 2007
In c# you can't use "", you must use \". Also you forgot to add a ; at the end of the line. The correct code is:

body.Attributes.Add("onLoad", "window.setTimeout(\"window.location.href='login.aspx'\"," & (Session.Timeout * 60 * 1000) + 5000 & ");");
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C# Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 11:30 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC