无法将值从服务器端设置为客户端中的文本框

本文关键字:客户端 文本 设置 服务器端 | 更新日期: 2023-09-27 17:56:23

我的代码是这样的

 <asp:TextBox type="text" name="txtEndDate" Text="<%#library.GetDictionaryItem("ProfilePages_CVR nummer")%>"  runat="server"></asp:TextBox>

对我来说一切看起来都很好,但我不知道为什么它会抛出错误

The server tag is not well formed.

无法将值从服务器端设置为客户端中的文本框

使用单引号,例如:

<asp:TextBox type="text" name="txtEndDate" Text='<%#library.GetDictionaryItem("ProfilePages_CVR nummer")%>'  runat="server"></asp:TextBox>

问题是由于 ASP.net 括号内包含双引号

<asp:TextBox Text="<%# someMethod("someValue") %>" />

在 Text 字段中,您需要在该属性上使用单引号而不是双引号,如下所示:

<asp:TextBox type="text" name="txtEndDate" 
    Text='<%# library.GetDictionaryItem("ProfilePages_CVR nummer")%>'  
    runat="server">
</asp:TextBox>

它会起作用。

另请注意,您使用的是数据绑定表示法 ( <%# ),仅当文本框位于 DataBound 控件内,或者在包含此文本框的控件或页面上调用 DataBind 时,该表示法才有效。