I'm trying to encapsulate the text box watermark into my own textbox control. My textbox control overrides the built-in textbox and adds various functions such as validators, etc. I've given it a property of WatermarkText, and when that property is used, I want to apply the watermark.
I've been using the following code in my textbox control:
protected override void CreateChildControls()
{
if (!string.IsNullOrEmpty(this.WatermarkText) && Microsoft.Web.UI.ScriptManager.GetCurrent(this.Page) != null)
{
this.Controls.Clear();
AtlasControlToolkit.TextBoxWatermarkExtender te = new AtlasControlToolkit.TextBoxWatermarkExtender();
watermarkProperties.TargetControlID = this.ID;
if (string.IsNullOrEmpty(watermarkProperties.WatermarkCssClass))
watermarkProperties.WatermarkCssClass = "TextBoxWatermark";
te.TargetProperties.Add(watermarkProperties);
Controls.Add(te);
}
}
This has been working fine on simple pages. But in the following scenario, it does not work:
Page -> multiview -> user control. So, either when it's part of a multiview, or usercontrol, it does not work. I get javascript errors.
Any ideas what to do? Or is this just a bug? Should I be using Controls.Add on the last line, or should I use:
Microsoft.Web.UI.ScriptManager.GetCurrent(Page).Controls.Add(te);
Both work on the regular page, but not on my more complex page.
Thanks!