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

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.

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

Thanks,
Kedar

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 & ");");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.