因为我发现从后面的代码添加所有占位符很烦人/烦人。您可以创建一个继承WebControls TextBox的新TextBox类,然后可以从CodeBehind或HTML Side添加占位符。
TextBox.cs(置于Project / Controls /中)
namespace Project.Controls
{
public class TextBox : System.Web.UI.WebControls.TextBox
{
public string PlaceHolder { get; set; }
protected override void OnLoad(EventArgs e)
{
if(!string.IsNullOrWhiteSpace(PlaceHolder))
this.Attributes.Add("placeholder", PlaceHolder);
base.OnLoad(e);
}
}
}
在Web.Config中注册控制:
(使用你想要的任何标签前缀)
用法:强>
或来自背后的代码
SomeId.PlaceHolder="This is a PlaceHolder";