mko
mko

Reputation: 7325

Pass only predefined value to user control property

I have created a user control and defined properties in order to pass values from .aspx page. As a next step I want to define values that a user control can accept in those properties.

For example if it is a property expecting a bool value, I want to be able to select either true or false, etc.

Not really sure how to start.

Upvotes: 0

Views: 205

Answers (1)

Ann L.
Ann L.

Reputation: 13965

Your question is a little vague, but here goes:

  1. If your property is boolean, there are only 2 possible values, so you don't need to do anything more.
  2. If you have a set of integer values, you could set them up as an Enum.
  3. If you have a set of string values, you might do better to rework them into an Enum and use one of several techniques (ask if you need to) to associate text with numeric values.

All of this assumes discrete values. If you have a range of continuous values (-1.000 to 1.000, or something like that) you will probably need to write validation code in the Getter and Setter of your property. Another option would be to use DataAnnotations on your underlying model.

If you just need to know how to prevent bad data from being entered into a web control within your user control, you need to look into validation controls.

Upvotes: 2

Related Questions