从asp:TextBox中获取占位符文本来自后面的代码字段

问题描述 投票:0回答:1

我有一个文本框

<asp:TextBox type="text" ID="txtFoo" runat="server"
    placeholder='<%=txtStartWriteToSearchCustomer %>' />

并且后面的代码包含

protected string txtStartWriteToSearchCustomer = "Start typing";

但是,文本框将获得占位符

代替

开始输入

省略撇号而不是使用placeholder=<%=txtStartWriteToSearchCustomer %>会使整个标签无效,而placeholder="<%=txtStartWriteToSearchCustomer %>"也会逐字输出文本。

如何在字段中将字符串放入占位符而不在后面的代码中写入assign语句?

edit

我已成功使用placeholder=<%#txtStartWriteToSearchCustomer %>并将DataBind();线放在Page_Load中。这似乎以我不太了解的方式扰乱了网页上其他元素的数据绑定。你必须按正确的顺序做事。我不想使用这种方法,因为它似乎增加了复杂性。

asp.net code-behind
1个回答
0
投票

你可以在后面的代码中使用它

txtFoo.Attributes.Add("placeholder", "Start typing");
© www.soinside.com 2019 - 2024. All rights reserved.