【问题标题】:Why the server side variable is not getting bound to the .aspx textbox?为什么服务器端变量没有绑定到 .aspx 文本框?
【发布时间】:2019-09-19 20:38:12
【问题描述】:
    Public Class frmFMECA
    Inherits System.Web.UI.Page

    Public LastFailureDate As String

并在 .aspx 中像这样使用它

 <asp:TextBox ID="txtLastFailureDate_GR" Text="<%= this.LastFailureDate %>" runat="server"></asp:TextBox>

但它除了 在文本框中没有显示任何内容。

【问题讨论】:

    标签: asp.net vb.net public


    【解决方案1】:

    您需要使用 DataBinding 表达式。

    Text='<%# this.LastFailureDate %>'
    

    如果 TextBox 不在 GridView、Repeater 等内部,则需要在 Page_Load 中手动调用 DataBind()

    protected void Page_Load(object sender, EventArgs e)
    {
        DataBind();
    }
    

    【讨论】:

    • 它说'this'没有被声明
    • 好的。 'Me' 之所以起作用,是因为这是 C# 保留关键字,而对于 vb,它是 Me
    • 我不知道,但不知何故 databind() 起作用了。我不知道为什么,你能解释一下它是什么以及它是如何知道的吗?
    • 如果您不调用 DataBind,值将不会绑定到控件。这就是为什么在使用Repeater 时调用Repeater1.DataBind()。参考docs.microsoft.com/en-us/dotnet/api/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-05
    • 1970-01-01
    相关资源
    最近更新 更多