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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:53:41+00:00 2026-05-11T13:53:41+00:00

<asp:DropDownList ID=ddl1 runat=server> <asp:ListItem Text=First Value=1></asp:ListItem> <asp:ListItem Text=Second Value=2></asp:ListItem> </asp:DropDownList> <asp:TextBox ID=tb1 runat=server/> <asp:Button

  • 0
<asp:DropDownList ID='ddl1' runat='server'>     <asp:ListItem Text='First' Value='1'></asp:ListItem>     <asp:ListItem Text='Second' Value='2'></asp:ListItem> </asp:DropDownList>  <asp:TextBox ID='tb1' runat='server'/>  <asp:Button ID='btn1' text='Go!' OnClick='btn1_Click' runat='server' />    public void btn1_Click(object sender, EventArgs e) {   } 

If the user selects the dropdown with text ‘First’, the data in the textbox has to be a number. If they selected ‘Second’, it has to be letters only.

How can I dynamically create a validation control, and change its behaviour?

I have tried creating the validation object, setting the control to validate to the textbox, and calling its Validate method in the btn1_click event but it didn’t work.

update

here is the code I tried:

public void btn1_Click(object sender, EventArgs e)     {         RequiredFieldValidator rfv1 = new RequiredFieldValidator();          rfv1.ID = 'rfv1';         rfv1.ControlToValidate = tb1.ID;         rfv1.Text = 'please enter a value for tb1';           rfv1.Validate();          Response.Write('<br>Page.IsValid: ' + Page.IsValid);      } 
  • 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. 2026-05-11T13:53:42+00:00Added an answer on May 11, 2026 at 1:53 pm
    • Option 1:
      Add both validators to the textbox and set them enabled/disabled based on the user selection.

    • Option 2:
      Use a custom validator that takes the dropdownlist into account (and maybe wrap it all into a custom control).

    Of these, I think I prefer option 1, but I’d have to try it to see how well it really works in the browser (how easy or is it possible to swap the enabled validator in javascript).

    You don’t want to add/remove the validator dynamically, because that has to be done server side and that means doing a post back when the user changes the dropdownlist selection to set the correct validator before you can validate the textbox. Both of my suggested solutions avoid that.

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

Sidebar

Related Questions

this is my drpdownlist <asp:DropDownList ID=DriverGender runat=server> <asp:ListItem Text=M Value=M></asp:ListItem> <asp:ListItem Text=F Value=F></asp:ListItem> </asp:DropDownList>
I have a dropdownlist with following options: <asp:DropDownList ID=ddlTaxStatus runat=server OnPreRender=ddlContainerStatus_PreRender> <asp:ListItem Text=--Select-- Value=-1></asp:ListItem>
I have the dropdownlist like this one : <asp:dropdownlist ID =ddlgender runat=server> <asp:ListItem Text=--Please
I have the following date dropdownlist options: <asp:DropDownList id=eventsDate runat=server> <asp:ListItem Value=04/31/2012>Apr 31, 2012</asp:ListItem>
I can do DropDownList <asp:DropDownList ID=YearList runat=server oninit=YearList_Init1 /> but I can't edit text
I have two DropDownList <asp:DropDownList ID=ddl1 runat=server Width=173px CssClass=ddl > </asp:DropDownList> <asp:DropDownList ID=ddl2 runat=server
<asp:DropDownList id=Code1 runat=server OnLoad=GetCode1 ValidationGroup=ValidateGroup/> <asp:RequiredFieldValidator ID=Code1_RequiredValidator runat=server ErrorMessage=Please select a value! ControlToValidate=Code1 ValidationGroup=ValidateGroup
If I use: OnSelectedIndexChanged like this: <asp:DropDownList ID=ddl1 AutoPostBack=true OnSelectedIndexChanged=Test_SelectedIndexChanged runat=server></asp:DropDownList> UpdatePanel and UpdateProgress
I have an ASP.NET dropdownlist like this: <asp:DropDownList ID=ddlMyDropDown runat=server> <asp:ListItem>Please pick one</asp:ListItem> <asp:ListItem>option1</asp:ListItem>
I've got the following DropDownList control: <asp:DropDownList ID=SubjectFilter runat=server AutoPostBack=True onselectedindexchanged=SubjectFilter_SelectedIndexChanged></asp:DropDownList> SubjectFilter data: BookStore

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.