我有一个文本框
<asp:TextBox type="text" ID="txtFoo" runat="server"
placeholder='<%=txtStartWriteToSearchCustomer %>' />
并且后面的代码包含
protected string txtStartWriteToSearchCustomer = "Start typing";
但是,文本框将获得占位符
代替
开始输入
省略撇号而不是使用placeholder=<%=txtStartWriteToSearchCustomer %>
会使整个标签无效,而placeholder="<%=txtStartWriteToSearchCustomer %>"
也会逐字输出文本。
如何在字段中将字符串放入占位符而不在后面的代码中写入assign语句?
我已成功使用placeholder=<%#txtStartWriteToSearchCustomer %>
并将DataBind();
线放在Page_Load
中。这似乎以我不太了解的方式扰乱了网页上其他元素的数据绑定。你必须按正确的顺序做事。我不想使用这种方法,因为它似乎增加了复杂性。
你可以在后面的代码中使用它
txtFoo.Attributes.Add("placeholder", "Start typing");