asp.net(发生错误).object引用未设置为对象的实例 [英] asp.net(an error occured).object reference not set to an instance of an object
本文介绍了asp.net(发生错误).object引用未设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
执行网页时发生错误。
对象引用没有设置为object.how来解决这个问题?
受保护 void Page_Load(对象发件人,EventArgs e)
{
尝试
{
if (!IsPostBack)
{
// string ID = Request.QueryString [Resources.PayrollResources.ID];
if (Session [Resources.PayrollResources.UserID]。 ToString()== )
{
Response.Redirect(Resources .PayrollResources.LoginPage);
}
else
{
LoadAllowanceData();
GetUserRight();
}
}
}
catch (例外情况)
{
Page.RegisterClientScriptBlock(Resources.PayrollResources.Blank,Resources.PayrollResources.JavaThrowMessage);
}
}
解决方案
我们不知道您的代码是什么这样做是不可能帮助你的。但是我会在下面的行放置一个断点并逐步检查
if (会话[ Resources.PayrollResources.UserID] .ToString()== )
我的假设是你将会话'的值转换为不存在的字符串变量,所以在分配之前将其检查为:
if (Session [Resources.PayrollResources.UserID]!= null )
{
// 添加您的代码
}
an error occured while executing a web page.
object reference not set to an instance of an object.how to solve this?
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
//string ID = Request.QueryString[Resources.PayrollResources.ID];
if (Session[Resources.PayrollResources.UserID].ToString() == "")
{
Response.Redirect(Resources.PayrollResources.LoginPage);
}
else
{
LoadAllowanceData();
GetUserRight();
}
}
}
catch (Exception ex)
{
Page.RegisterClientScriptBlock(Resources.PayrollResources.Blank, Resources.PayrollResources.JavaThrowMessage);
}
}
解决方案
We do not know what your code is doing so it is impossible to help you. But I would have placed a breakpoint at the below line and check step by step
if (Session[Resources.PayrollResources.UserID].ToString() == "")
And my assumption is you are converting session''s value to a string variable when it does not exist so before assigning check it as:
if (Session[Resources.PayrollResources.UserID] != null) { //add your code }
这篇关于asp.net(发生错误).object引用未设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文