在下一页中创建会话并获取会话值 [英] Create Session and get Session value in next page

查看:65
本文介绍了在下一页中创建会话并获取会话值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我是ASP.Net和C#的新手。

我无法理解什么是会话。

例如,我可以在aspx.cs页面中创建一个会话,如...

Hi all,

I am new to ASP.Net and C#.
I can''t understand what is session.
For example, I can create a Session in aspx.cs page like...

session.add("userid", txtusername); 



但我不知道,这是什么以及如何在下一页获得用户ID?



请帮帮我。


but I don''t know, what is this and how can I get the user id in next page ?

Please help me.

推荐答案

亲爱的会话是一个包含你想携带的信息的对象结束

假设在你的page1.aspx中有一个测试盒,其ID是txt_user和一个按钮

如果你想在下一页中使用这个测试,我们可以说它是page2.aspx

你必须这样使用

对于按钮点击事件

使用会话对象
Dear Session is an object which contain information which you want to carry over
Suppose in your page1.aspx there is a test box whose ID is txt_user and a button
And if you want to use this test into next page lets say it is page2.aspx
You have to use like this
For a button click event
use session object
Session["your_session_variable_name"].ToString()=txt_user.Text;



这将包含会话变量中的文本框值,然后您可以在下一页中使用它,就像这样


and this will contains the text box value in session variable then you can use it in next page like this

String your_name=Session["your_session_variable_name"].ToString();



现在你可以使用这个字符串直到会话默认结束或你杀了它


And now you can use this string till the session ends by default or you kill it


你可以在Session变量中添加任何内容,但之后需要向下转发..



例如:




ASP.NET中的


会话[对象] =任何内容



代码C#

任何东西x =(任何)会话[对象];
You can add anything in a Session variable but you need to downcast it afterwards..

for example:


in ASP.NET
Session["object"] = anything

CODE BEHIND C#
anything x = (anything) Session["object"];





在另一页中, Session [userid]。ToString()返回会话变量userid。 />


有关会话的更多信息:在ASP.NET中探索会话 [ ^ ]



希望这会有所帮助。
Hi,

In another page, Session["userid"].ToString() returns the session variable "userid".

More information about Session: Exploring Session in ASP.NET[^]

Hope this helps.


这篇关于在下一页中创建会话并获取会话值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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