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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:06:13+00:00 2026-06-03T17:06:13+00:00

I have a form, backed by a ViewModel that’s wrapping an ORM object that

  • 0

I have a form, backed by a ViewModel that’s wrapping an ORM object that is mapping a database record that contains a “territory” field.

The business logic for this field is toggled by a “ValidateTerritory” configuration flag. If the flag is turned on, then the field has to contain one of the values in the Territories table. In this case, my view should contain a ComboBox that is populated with these territories. This I could handle, simply enough: include a ValidTerritories property on the ViewModel that is populated from the database, and bind the ComboBox’s ItemsSource to that property. And, of course, bind the ComboBox’s SelectedValue to the territory field in the ORM.

The problem is that if the “ValidateTerritory” flag is turned off, there are no validation rules on this field. It’s a plain text field containing any unconstrained value. In which case my view should contain a TextBox, with it’s Text property bound to the field in the ORM.

The question is: what is the cleanest way of handling this – toggling the control on the form from one type to another, based on the value of that configuration object?

  • 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-06-03T17:06:16+00:00Added an answer on June 3, 2026 at 5:06 pm

    I’d consider using a ContentControl that binds to the ‘full’ data (i.e. Content="{Binding }") and has a DataTemplateSelector that returns a data template containing a ComboBox (with the right bindings) or a data template containing a TextBox (again, the bindings are in the DataTemplate).

    This way you don’t have validation issues, no performance cost of loading a control that is collapsed and more flexibility in the future to have other controls in that role (maybe, an AutoComplete).

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

Sidebar

Related Questions

I have a form that contains and form of which code goes like this
I have form where user submits field. Field can have letters, numbers, and punctuation.
I have a simple form that I wish to postback to the server in
I have a form generator that uses (perl compatible) regexes for ther backend validation.
I have a form that get's processed via jQuery Ajax. Everything works well on
I have a registration form that is rendered by the following urlconf -- url(r'^$',
I have a Rails form with a checkbox on a boolean field. I want
ASP.NET apps that I've developed (on ASP.NET 2.0) have typically been backed by a
I have a django form that first validates its data through calling form.is_valid(). If
I need to present a form that is not backed by an AR model.

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.