asp.net 程序代码解释
我从前台传过数值(string类型),然后调用GetTd_TypeByTypeEname(Ename)方法得到一条纪律,
int aa = cont.TypeId;取到记录的id,
运行时提示蓝色标注代码“ 未将对象引用设置到对象的实例”我断点调试,发现aa 有值,但是最后id的值还是0,这是怎么回事,ViewState["id"] = aa;代表什么意思啊!
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string get = Request.QueryString["id"].ToString();
string[] array = get.Split('_');
string Ename = array[1];
cont = Td_TypeManager.GetTd_TypeByTypeEname(Ename);
int aa = cont.TypeId;
ViewState["id"] = aa;
int id = 0;
if (array[1] == "4")
{
id = 9;
} if (array[1] == "2")
{
id = 11;
}
if (array[1] == "5")
{
id = 6;
}
if (array[1] == "6")
{
id = 8;
}
if (array[1] == "7")
{
id = 7;
}
if (array[1] == "8")
{
id = 7;
}
Td_Kword kword = Td_KwordManager.GetTd_KwordByKwordId(id);
LtlKword.Text = "<title>" + kword.KwordTitle + "</title><meta name=\"keywords\" content=\"" + kword.KwordKey + "\" /><meta name=\"description\" content=\"" + kword.KwordDescribe + "\"/>"; LitTitle.Text = Td_TypeManager.GetTd_TypeByTypeId(Convert.ToInt32(array[1])).TypeName;
LitMtype.Text = Td_TypeManager.GetTd_TypeByTypeId(Convert.ToInt32(array[1])).TypeName;
Databinds();
}
[解决办法]
ViewState["id"] 类似cookie,但作用域只是当前页面
cookie你在页面pageload赋值时,当前是取不到刚赋的值,只有再刷新一次才能取到
[解决办法]
ViewState 是页面缓存 当页面在此刷新的时候 可以从ViewState里面取 你看生成的代码 里面就会有
[解决办法]
Td_Kword kword = Td_KwordManager.GetTd_KwordByKwordId(id);
kword没取到值为null吧
array[1] == "5"是不是没有可比性 啊
这个有没有可比性你自己最清楚啊,你接收的数据什么意义难道不知道吗