为会话分配值 [英] Assigning a value to a session

查看:106
本文介绍了为会话分配值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个带有图像按钮作为模板字段的dataList。并且标签上有一个名字。

我试图让按钮启动一个新页面并将标签的值传递给会话。



我试过这段代码,但它一直说对象引用未设置为对象的实例。



  protected   void  ImageButton1_Click( object  sender,ImageClickEventArgs e) 
{
标签lk =(标签)DataList1.FindControl( APP01Label );
会话[ testName] = lk.Text;
ClientScript.RegisterStartupScript( this .GetType(), myalert alert(' + Session [ testName]。ToString()+ '); true );
}





这里我想通过在消息框中显示会话值来测试它。



谢谢

解决方案

我怀疑错误发生在这一行: Session [testName ] = lk.Text 因为上一行可能找不到名称为 APP01Label 的控件。

我建议您更改代码如下: if(lk!= null){Session [testName] = lk.Text; }

Hi
I have a dataList with an image button as template field. and a label holds a name.
I trying to make the button fire up a new page and pass the value of the label to a session.

I tried this code but it keep saying "Object reference not set to an instance of an object".

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    Label lk = (Label)DataList1.FindControl("APP01Label");
    Session["testName"] = lk.Text;
    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Session["testName"].ToString() + "');", true);
}



here I want to test it by showing the Session value in a message box.

thanks

解决方案

I suspect that the error is happening on this line: Session["testName"] = lk.Text because the previous line may not find a control with the name APP01Label.
I would suggest that you change the code like this: if( lk != null ){ Session["testName"] = lk.Text; }


这篇关于为会话分配值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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