我在 asp.net 中动态生成文本框并在其上设置默认文本。现在,我想在文本框第一次成为焦点时清除它,但如果用户不输入任何内容,请再次显示默认文本。
protected void btnAdd_Click(object sender, EventArgs e)
{
TextBox textName;
textName = new TextBox();
textName.Text = "mail";
TextBox textName2;
textName2 = new TextBox();
textName2.Text = "tel";
string divContect = ControlRenderer(divTextBox);
divTextBox.InnerHtml = divContect + ControlRenderer(textName) + "  " + ControlRenderer(textName2) + "<br/><br/>";
}
public string ControlRenderer(Control control)
{
StringWriter writer = new StringWriter();
control.RenderControl(new HtmlTextWriter(writer));
return writer.ToString();
}