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

  • Home
  • SEARCH
  • 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 4022476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:28:47+00:00 2026-05-20T10:28:47+00:00

I have a form representing a survey that is dynamically generated based on some

  • 0

I have a form representing a survey that is dynamically generated based on some database configuration. I have a custom server control for rendering the survey (SurveyRenderer) which contains custom server controls for rendering questions (QuestionRenderers). I dynamically add RequiredFieldValidators for questions if they are flagged as being required. I add these validators to the SurveyRenderer‘s control collection.

The gist of the code…

// In SurveyRenderer.CreateChildControls()...
foreach (QuestionRenderer questionRenderer in questionRenderers)
{
   if (questionRenderer.Question.IsRequired)
   {
       Controls.Add(CreateRequiredValidator(questionRenderer));
   }
}

The client-side validation works fine — if someone has omitted a required question, the validators catch it and the form doesn’t validate. However if I turn off JavaScript and submit an invalid form, the validators do not seem to work.

On the server-side I am calling Page.Validate() and checking Page.IsValid in the submit button click event handler. Despite submitting a form where required questions have been left blank – something that would be caught client-side – on the server-side Page.IsValid remains True.

// In SurveyPage.aspx...
public void btnSubmit_Click(object sender, EventArgs e)
{
   Page.Validate();
   if (Page.IsValid)
   {
       // Always get here, even though the form is not valid and would
       // have been caught client-side...
   }
}

Should I be adding the validators to the Page’s Control collection, rather than the SurveyRenderer? How come it works on the client-side but not server-side?

UPDATE: My QuestionRenderer is annotated with:

[ValidationProperty("IsValid")]

And the IsValid get method is like so:

// QuestionRenderer.IsValid
public bool IsValid
{
    get
    {
        EnsureChildControls();
        if (Question.IsRequired && QuestionIsNotAnswered())
        {
            return false;
        }

        return true;
    }
}

If I set a breakpoint and step through, I can see that QuestionRenderer.IsValid is being fired OK. It is returning false when it should do. If I go fine-grained and call in btn_submitClick:

// In SurveyPage.aspx...
public void btnSubmit_Click(object sender, EventArgs e)
{
    foreach (IValidator validator in Page.Validators)
    {
        validator.Validate();  // this calls through to QuestionRenderer.IsValid, which returns false...
        bool valIsValid = validator.IsValid; // yet this is set to True
    }
}

So validator.IsValid is true, even though the call to QuestionRenderer.IsValid returns false. So maybe I haven’t wired something up correctly? Is using [ValidationProperty("IsValid")] not enough?

  • 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-20T10:28:48+00:00Added an answer on May 20, 2026 at 10:28 am

    actually, validation uses Page.Validators where all the validators are stored (the actual routine is quity tricky) – so it does not matter, where you add them.

    source of BaseValidator

    protected internal override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        this.Page.Validators.Add(this);
    }
    

    i would leave them in th view, as you could use object sender-parameter (which represents the validator) to get the associated control …

    i believe, your CreateChildControls – which does the attaching of the validators – is called to late, so it misses the validation phase …
    could you maybe try to call EnsureChildControls in OnLoad-event, to see if it changes something?
    another chance might be, that your validators are not visible or disabled…

    EDIT

    according to your edits, i would encourage you to use a CustomValidator – a RequiredFieldValidator will return true on each case (property is true or false), because it is not empty 🙂

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

Sidebar

Related Questions

I have a form with some radio buttons that are disabled by default. When
I have a form that contains a GridView control which is databound to an
I have form that displays several keywords (standard set of choice lists that changes
I have a form in C# that has a button that, when clicked, I
I have subclassed Form to include some extra functionality, which boils down to a
I have a form element that contains multiple lines of inputs. Think of each
I have a script that appends some rows to a table. One of the
I have a RichTextBox control on my form. The control is setup in such
I have form area in my view. If I click button A , I
I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>

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.