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 7638855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:16:29+00:00 2026-05-31T08:16:29+00:00

I have a custom UserControl which contains several TextBoxes with Validators. One TextBox with

  • 0

I have a custom UserControl which contains several TextBoxes with Validators. One TextBox with corresponding Validator is optional based on a CheckBox. Pseudo:

My Control.ascx:

<asp:TextBox id="txtAddress" />
<asp:Validator id="valAddress" />

<asp:CheckBox id="condition" />
<asp:TextBox id="txtConditional" />
<asp:Validator id="valConditional" ValidationGroup="ConditionalGroup" />

My Control.ascx.cs

public void Validate() {
    if(condition.Checked) {
        Page.Validate("ConditionalGroup");
    }
}

I also have a page which basically looks like this:

Page.aspx

<my:Control id="myControl" />

<asp:Button onClick="doPost" />

Page.aspx.cs

protected void doPost(object sender, EventArgs e) {
    myControl.Validate(); //This feels wrong

    if(Page.IsValid) {
        //go
    }
}

This all works, however I would like to take the myControl.Validate() line out of the Page.aspx.cs and put it in the My Control.ascx.cs. Putting it in the Page_Load of the control is not an option because the conditional checkbox value is always false. There is no event available after Page_Load and before the doPost click handler is fired…

It feels wrong to call the custom Validate function on the Page where I think it should belong somewhere in the UserControl. Is it true that this is architecturally wrong? Is there another solution for this maybe by using an event handler?

  • 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-31T08:16:30+00:00Added an answer on May 31, 2026 at 8:16 am

    You could try by enabling the validator only if the user checks on the check box. And disable the validator if the unchecks it. This has to be done in the user control. It can be done in the client side or in the server side. In this way, the page would validate all the validators that are enabled for the page.

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

Sidebar

Related Questions

I have a UserControl which contains a TextBox and a CustomValidator. I would like
I have a custom WPF control which consist of single TextBox <UserControl HorizontalAlignment=Left x:Class=WPFDiagramDesignerControl.Components.UcWBSBlock
I have a custom UserControl which tries to recreate auto-complete for a textbox. When
I have a custom user control (ascx) that contains a textbox and a Javascript-based
I have a custom UserControl which has a DependencyProperty ItemTemplate of type DataTemplate. I
How to Bring (form_x) to the front. I have a custom usercontrol which opens
If I have a custom user control (say, MyCustomControl.ascx) which contains a number of
I have created Custom User Control which contain TextBox and PasswordBox. it is binding
I have a custom UserControl with an image and a label, both of which
I have a custom DepenencyProperty which determines a UserControl's visibility. It is usually bound

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.