HTTPContext.Current.User.Identity.Name不是一个控件内部工作吗? [英] HTTPContext.Current.User.Identity.Name not working inside a control?

查看:112
本文介绍了HTTPContext.Current.User.Identity.Name不是一个控件内部工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签,我想设置这个标签的文本

  HTTPContext.Current.User.Identity.Name

所以我写了

 文本='<%= HTTPContext.Current.User.Identity.Name%GT;'

但它不工作,但是,当我写这个拉布勒之外,例如:

 < H2>
&所述;%= HTTPContext.Current.User.Identity.Name%GT;
< / H>

它的工作原理。


解决方案

 < ASP:标签ID =lbUserName
           =服务器
           文字='<%#HttpContext.Current.User.Identity.Name%GT;'
            />

在Page_Load中

 如果(!Page.IsPostBack)
{
   lbUserName.DataBind();
}

I have a label and I want to set text of this label to

HTTPContext.Current.User.Identity.Name

So I wrote

Text = '<%=HTTPContext.Current.User.Identity.Name %>'

but it doesn't work, however when I wrote this outside of the lable for example:

<h2>
<%=HTTPContext.Current.User.Identity.Name %>
</h2>

it works.

解决方案

<asp:Label ID="lbUserName" 
           runat="server"
           Text='<%# HttpContext.Current.User.Identity.Name %>'
            />

in Page_Load

if (!Page.IsPostBack )
{
   lbUserName.DataBind();
}

这篇关于HTTPContext.Current.User.Identity.Name不是一个控件内部工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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