I have a class.cs file as following, but there is an error for my "Page.ClientScript", which said "an object reference is required for the non-static field, method, or property 'System.Web.UI.Page.ClientScript.get'". So I. wonder is the page.clientscript is not available to used in class.cs? Any other method to use instead of page.clientscript ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.Data;
using System.Web.Script.Services;
public class SessionExpired
{
public SessionExpired()
{
string csname = "timeoutWarning";
Type cstype = this.GetType();
if (!Page.ClientScript.IsStartupScriptRegistered(cstype, csname))
{
string strconfirm = "<script>" +
"window.setTimeout('SessionTimeOutHandler()', 60000);" +
"function SessionTimeOutHandler() { " +
"alert('Your login session is expired');" +
"window.location='../Processing.aspx';" +
"}</script>";
Page.ClientScript.RegisterStartupScript(cstype, csname, strconfirm, false);
}
}
}
You are having problems because it looks like you are using a class which doesn't derive from
System.Web.UI.Page
. However, as long as you have access toHttpContext
, you can just say: