在aspx文件中使用内联代码设置文字文本 [英] Set literal text with inline code in aspx file

查看:89
本文介绍了在aspx文件中使用内联代码设置文字文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET项目中,我有一个文字.为了设置text属性,我使用了以下代码:

In an ASP.NET project, I have a literal. In order to set the text property, I used the following code:

<asp:Literal ID="ltUserName" runat="server" Text="<%= session.UserName %>" />

但文字而不是 session.UserName 的值,而是显示<%= session.UserName%> .我觉得解决方案很简单,但我做不到.如何使用内联代码设置文本?

But instead of value of session.UserName, literal shows <%= session.UserName %>. I feel that solution is simple but I couldn't do it. How can set the text with inline code?

推荐答案

如果您确实想在HTML页面中打印会话值,请使用<%= Session ["UserName"].ToString()%>作为<%%>"将充当服务器标记,您不能在文字控件内提供它

If you actually want to print the session value in the HTML page just use <% =Session["UserName"].ToString()%> as "<% %> will act as server tag and you cant give it inside the literal control

我的意思是不需要文字控制可以只使用提到的编码而不是文字.

I mean no need of Literal Control can just use mentioned coding instead of literal.

这篇关于在aspx文件中使用内联代码设置文字文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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