是否可以在文本框ASP.NET中使用多行占位符?

时间:2017-08-16 04:57:55

标签: asp.net placeholder multiline

placeholder="(e.g. 1, (in new line)2,(in new line)3,(in new line)4, ...)"

示例:文本框看起来像:

如何继续使用此占位符的下一行?

1 个答案:

答案 0 :(得分:1)

首先将文本框的TextMode设置为MultiLine

<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Rows="3"></asp:TextBox>

您可以在Page_Load方法中添加placeholder属性并使用Environment.NewLine或字符串文字&#34; \r\n&#34;添加换行符。像:

protected void Page_Load(object sender, EventArgs e)
{
    TextBox1.Attributes.Add("placeholder", "1,"+Environment.NewLine+"2," + Environment.NewLine + "3,");
    //or using \r\n:
    TextBox1.Attributes.Add("placeholder", "1,\r\n2,\r\n3,");
}

输出结果为:

希望它会帮助你......!