Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:37:05+00:00 2026-05-30T06:37:05+00:00

I have a custom composite control that contains a text box, some validators, as

  • 0

I have a custom composite control that contains a text box, some validators, as well as several UI components. I am unable to get the client side validation to work at all. The server side validation works fine after the postback. I was ultimately planning to add custom CSS to the TextBox on validation failure by hooking into the validation API, but I can’t even get the client side validation running.

Since this control was intended to be generic, the validators are not generated from within the composite control itself but passed in from externally as follows.

    <mycontrol:HighlightedTextbox ID="HighlightedTextbox1" runat="server" Label="test" CssClass="generalText" FocusedCssClass="highlightText" ErrorCssClass="errorText">
      <validators>
        <asp:RequiredFieldValidator ID="required1" runat="server" ErrorMessage="Field is required" EnableClientScript="true" />
      </validators>
      <prompttemplate><span>this is a prompt</span></prompttemplate>
    </mycontrol:HighlightedTextbox>

I have the persistchildren attribute specified (I believe appropriately) so that the validators are in fact added to the Validators property. That appears to be working fine as well.

    [PersistChildren(true, true), ParseChildren(true), PersistenceMode(PersistenceMode.InnerProperty)]
    public abstract class BaseHighlightedControl<TControl> : CompositeControl
      where TControl : Control

I have a derived control that specifies a standard TextBox as TControl as well as exposing a text property but that is really all the derived type does. The composite control relies on the CreateChildControls method to build out the control and configure the validators. This seems like it should be an appropriate in the life-cycle since I have seen examples of composite controls that create validators in the CreateChildControls method.

    public List<BaseValidators> Validators { get; private set; }

    /// <summary>
    /// Create the child controls
    /// </summary>
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        this.MainControl.ID = "HighlightControl";

        this.PromptTemplate.InstantiateIn(this.Prompt);
        this.Prompt.Style.Add(HtmlTextWriterStyle.Display, "inline");
        this.FieldLabel.Text = this.Label;

        if (!this.DesignMode)
        {
            this.Controls.Add(this.FieldLabel);
            this.Controls.Add(this.MainControl);
            this.Controls.Add(this.Prompt);
            AddValidators();
        }
    }

    private void AddValidators()
    {
        foreach (var validator in this.Validators.OfType<BaseValidator>())
        {
            validator.ControlToValidate = this.MainControl.ID;
            validator.ValidationGroup = this.ValidationGroup;
            validator.Display = ValidatorDisplay.Dynamic;

            this.Controls.Add(validator);
        }
    }

Again, the server side validation takes place just fine. The Page_Validators collection in javascript doesn’t ever contain my validators. Any validators that I add to the markup outside of my control appear in the javascript collection just fine and work appropriately.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:37:07+00:00Added an answer on May 30, 2026 at 6:37 am

    The issue was caused by my attempt to create the validator controls inside asp.net markup and then pass them into the composite control later. For some reason that I don’t quite understand, the validator control’s life-cycle seemed to be a bit messed up even though they were never actually added to the control tree until the composite control put them there. The intent was that they would get created in markup and configured and loaded by the composite control. I simply used the template system instead of a control collection property. It isn’t quite what I wanted since other controls can be added, but it works flawlessly since the controls are now instantiated in the CreateChildControls method. It now looks like this.

        public ITemplate Validators { get; set; }
    

    instead of

        public List<BaseValidators> Validators { get; private set; }
    

    The CreateChildControls method now does standard template instantiation

        this.ValidatorsTemplate.InstantiateIn(this.ValidatorContainer);
    

    I then recursively walk the ValidatorContainer controls (careful to avoid infinite recursion) looking for validators which I configure by setting the ControlToValidate and some other things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a master 'composite custom server control', with several child custom controls,
I have a custom control that inherits from .NET's CompositeControl class. This control overrides
I have created a custom server control that inherits from CompositeControl. In the CreateChildControls
I have a custom server control (composite control having dynamically created dropdown boxes and
I have custom coded several enterprise applications for mid to large organizations to use
I have custom classes that I currently instantiate within App.xaml as resources. I want
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
I have a few models that need to have custom find conditions placed on
I am creating a custom composite control based off of an asp:Label control. I'd
I'm having a problem creating a new CompositeControl. Currently I have a custom control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.