[英]How can I display the value stored in my Session Variable in my code behind, in HTML?
What I am trying to achieve is to get my session variable called Session["name"]
in my code behind file and display it on the browser using HTML. 我要实现的目标是在代码后的文件中获取名为
Session["name"]
会话变量,并使用HTML将其显示在浏览器中。
What I had tried initially was to place the session between <%%> tags but that did not work. 我最初尝试的是将会话放置在<%%>标记之间,但这没有用。
This is a line of code from my code behind file: 这是我文件后面的代码中的代码行:
string.Format("Welcome, {0}", Session["name"].ToString().Split(' ')[0]);
What is the best way for me to simply display my welcome message using C# and HTML? 对我来说,使用C#和HTML简单地显示欢迎消息的最佳方法是什么? I saw stuff about JSON but I really don't understand it nor where to start if that is the route id need to take.
我看到了有关JSON的内容,但我真的不了解它,也不清楚从哪里开始(如果那是需要使用的路由ID)。 Please advice.
请指教。
You are already creating a session to store name : 您已经在创建一个会话来存储name:
//Create
Session["name"] = value;
Now to show it on the front end or html page you can use label and set text value of that label to the session value as string 现在将其显示在前端或html页面上,您可以使用label并将该标签的文本值设置为会话值作为字符串
//Set session text to label
Label1.Text = Session["name"].ToString();
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.