protected void TextBox1_Init(object sender, EventArgs e)
{
// get the text box
TextBox tb=(sender as TextBox);
// read the ASP tooltip as the watermark text
string defaulttext = tb.ToolTip;
// if the field is blank, set text to the tooltip
// this only fires of on init of the page, not as
// the user is navigating around on it.
if (tb.Text == "") { tb.Text = tb.ToolTip; }
// hook up the JavaScript events to the screen objects.
tb.Attributes.Add("onFocus", "doClear(this)");
tb.Attributes.Add("onBlur", "doBlur(this)");
//init the screen objects (only on init)
if (tb.Text == "")
{
tb.CssClass = "watermarked";
tb.Text = tb.ToolTip;
}
else
{
TextBox1.CssClass = "unwatermarked";
}
}