我想从code属性值的背后 [英] I want to get property value from code behind
本文介绍了我想从code属性值的背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我需要从code后面没有设置Text属性在aspx页面的ASP标签的情况。更确切地说,我需要设置一个值,在ASP aspx页面控制和这个值是通过在同一页面code后面的属性设置。
所以我需要使用前pression做到这一点,如:
< ASP:标签文本=<%= myProperty的%GT; ... />
我使用的:
<%= myProperty的%GT;不工作。
<%#myProperty的%GT;不还。
解决方案
Default.aspx.cs
公共部分类_Default:System.Web.UI.Page
{
公共字符串CustomTitle =这是标题; 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
的Page.DataBind();
}
}
Default.aspx的
< ASP:标签文本='<%#CustomTitle%GT;' =服务器/>
I have a case that I need to set the Text property for an asp label in the aspx page not from code behind. More exactly, I need to set a value to asp control in aspx page and this value is set by a property in the same page code behind.
so I need to use an expression to do that like:
<asp:Label Text="<%= MyProperty %>" ..../>
I use:
<%= MyProperty %> doesn't work.
<%# MyProperty %> doesn't also.
解决方案
Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
public string CustomTitle = "This Is Title";
protected void Page_Load(object sender, EventArgs e)
{
Page.DataBind();
}
}
Default.aspx
<asp:Label Text='<%#CustomTitle %>' runat="server" />
这篇关于我想从code属性值的背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文