asp.net – 我希望从代码中获取属性值

前端之家收集整理的这篇文章主要介绍了asp.net – 我希望从代码中获取属性值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个案例,我需要在aspx页面中为asp标签设置Text属性,而不是从后面的代码.更确切地说,我需要在aspx页面中为asp控件设置一个值,并且该值由后面相同页面代码中的属性设置.

所以我需要使用表达式来做到这一点:

  1. <asp:Label Text="<%= MyProperty %>" ..../>

我用:

  1. <%= MyProperty %> doesn't work.
  2. <%# MyProperty %> doesn't also.

解决方法

Default.aspx.cs
  1. public partial class _Default : System.Web.UI.Page
  2. {
  3. public string CustomTitle = "This Is Title";
  4.  
  5. protected void Page_Load(object sender,EventArgs e)
  6. {
  7. Page.DataBind();
  8. }
  9. }

Default.aspx的

  1. <asp:Label Text='<%#CustomTitle %>' runat="server" />

猜你在找的asp.Net相关文章