对象引用未设置为对象的实例“当将值从子页面初始化到会话页面到主页面功能时 [英] Object reference not set to an instance of an object "when initializing value into session from child page to master page function

查看:75
本文介绍了对象引用未设置为对象的实例“当将值从子页面初始化到会话页面到主页面功能时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

母版页





master page


OrdrInfo ordinfo = (OrdrInfo)Session["addtocartlist"]; // OrdrInfo is class where i have arraylist.
shopCarInfor(ordinfo);

public void shopCarInfor(OrdrInfo order)
{

Session["addtocartlist"] = order;
}


//till now there is no problem. .

///child page:

protected void c1_row_command(object sender, C1GridViewCommandEventArgs e) // when this function calls using command name 
{
if (e.CommandName.ToLower() == "delete")
{
// i am deleting particulars and binding into class
OrdrInfo model = (OrdrInfo)Session["addtocartlist"];

}
//there is some needed that i need to update class value from child page to master pager 
//so, i called like below,
project.MasterPage.Site1 objsite = new MasterPage.Site1();

objsite.shopCarInfor(model);

}

//this objsite.shopCarInfor(model); calls correctly which is in master page also i am getting //value here

public void shopCarInfor(OrdrInfo order) // i am getting value in order
{

Session["addtocartlist"] = order; // when initializing order to session , i am getting error like "Object reference not set to an instance of an object".

}



如何解决这个问题?需要帮助。


how to solve this problem? help needed.

推荐答案





我不知道你为什么要创建新的实例你掌握页面。



你可以打电话给它打电话



Hi,

I don't know why you are creating new instance of you master page.

you can call it call the same as

Master.[Your function]





你必须指定母版页





you must specify the master page

<%@ MasterType virtualpath="~/Masters/Master1.master" %>





有关母版页的更多信息: http://msdn.microsoft .com / zh-cn / library / vstudio / xxwa0ff0(v = vs.100).aspx [ ^ ]



我没有看到任何错误代码,但你发布主页和内容页面然后我更清楚地理解。



For more information on Master Page : http://msdn.microsoft.com/en-us/library/vstudio/xxwa0ff0(v=vs.100).aspx[^]

I did not saw any erroneous code but you post the both master and content page then I more clear to understand.


这篇关于对象引用未设置为对象的实例“当将值从子页面初始化到会话页面到主页面功能时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆