Encapsulating extenders

Last post 05-01-2006 6:06 PM by sburke_msft. 3 replies.

Sort Posts:

  • Encapsulating extenders

    04-30-2006, 12:38 AM
    • Member
      60 point Member
    • riverhawk79
    • Member since 04-30-2006, 4:33 AM
    • Posts 12
        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!
  • Re: Encapsulating extenders

    05-01-2006, 11:45 AM
    • Contributor
      4,346 point Contributor
    • sburke_msft
    • Member since 04-04-2006, 3:28 PM
    • Redmond, WA
    • Posts 770
    • AspNetTeam

    Your Add call should add the extender in the same naming scope as it's target.  But in the example above, what is the parent control?  A Textbox or another control that contains a textbox and the extender? 

    In any case, what are the Javascript errors you're seeing?

    Don't forget, this posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Encapsulating extenders

    05-01-2006, 4:27 PM
    • Member
      60 point Member
    • riverhawk79
    • Member since 04-30-2006, 4:33 AM
    • Posts 12
    the parent control is a textbox that inherits from the asp.net textbox.

    When i use Microsoft.Web.UI.ScriptManager.GetCurrent(Page).Controls.Add(te);...i get the following javascript error:

    Target control with ID "TextBoxName" could not be found for extender.

    Again, when i put it on a simple page, it works beautifully.  But in the scenario of Page -> multiview -> user control, i get that error.

    But I think there's an issue in general with this extender and user controls, or multiviews, because even if I put the extended into the markup it still does the same thing.

  • Re: Encapsulating extenders

    05-01-2006, 6:06 PM
    • Contributor
      4,346 point Contributor
    • sburke_msft
    • Member since 04-04-2006, 3:28 PM
    • Redmond, WA
    • Posts 770
    • AspNetTeam

    The issue here is that the extender can't find the target.  Internally the extender does (basically):

    NamingContainer.FindControl(TargetControlID);

    If that comes back null, you'll get the error you're seeing.  Go ahead and paste in your markup-only repro and maybe I can spot the issue.

    Don't forget, this posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 1 (4 items)