【问题标题】:Is it possible to have a multiline placeholder in a textbox ASP.NET?是否可以在文本框 ASP.NET 中使用多行占位符?
【发布时间】:2018-01-24 02:43:15
【问题描述】:
placeholder="(e.g. 1, (in new line)2,(in new line)3,(in new line)4, ...)"

示例:文本框将如下所示:

如何为这个占位符继续下一行?

【问题讨论】:

标签: asp.net placeholder multiline


【解决方案1】:

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

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

您可以在Page_Load 方法中添加placeholder 属性并使用Environment.NewLine 或字符串文字“\r\n”添加换行符,例如:

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,");
}

输出是:

希望对你有所帮助..!

【讨论】:

  • 当我将您的代码保存到我的 bin 文件夹时,我为这些类型的代码使用什么扩展?
  • 为什么你需要用扩展保存它?。您的文本框控件位于 .aspx 页面中,page_load 函数位于 .aspx.cs 页面中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-28
  • 1970-01-01
  • 1970-01-01
  • 2011-11-03
  • 2021-10-03
  • 1970-01-01
相关资源
最近更新 更多