Huzaifa
April 9th, 2003, 03:41 AM
hi
i have a class file having a common error trapping function
whenever any error in the project occurs like session expiry etc.
it should display the error or goto login page depending on the type of error.
error i am getting is
System.Web.HttpException: Response is not available in this context.
also can u help me in finding out the error number
thanks
huzaifa
check out the code
common.cs file
--------------------
using System;
using System.Text;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
namespace XYZ
{
public class common:System.Web.UI.Page
{
public common()
{
}
public void DispError(string errormsg,Label lblMessage)
{
if(errormsg.Equals("Object reference not set to an instance of an object.") || errormsg.Equals("Fill: SelectCommand.Connection property has not been initialized."))
{
Response.Write ("script window.parent.location.href='../login.aspx' /script ");
lblMessage.Text=errormsg;
}
else
{
lblMessage.Text=errormsg;
}
}
}
}
view.aspx.cs file
------------------
try{
connection code and database handling
..........
}
catch(Exception ex)
{
common cs=new common();
cs.DispError(ex.Message,lblMessage);
}
i have a class file having a common error trapping function
whenever any error in the project occurs like session expiry etc.
it should display the error or goto login page depending on the type of error.
error i am getting is
System.Web.HttpException: Response is not available in this context.
also can u help me in finding out the error number
thanks
huzaifa
check out the code
common.cs file
--------------------
using System;
using System.Text;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
namespace XYZ
{
public class common:System.Web.UI.Page
{
public common()
{
}
public void DispError(string errormsg,Label lblMessage)
{
if(errormsg.Equals("Object reference not set to an instance of an object.") || errormsg.Equals("Fill: SelectCommand.Connection property has not been initialized."))
{
Response.Write ("script window.parent.location.href='../login.aspx' /script ");
lblMessage.Text=errormsg;
}
else
{
lblMessage.Text=errormsg;
}
}
}
}
view.aspx.cs file
------------------
try{
connection code and database handling
..........
}
catch(Exception ex)
{
common cs=new common();
cs.DispError(ex.Message,lblMessage);
}