Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class validation with Web UI

Status
Not open for further replies.

RicksAtWork

Programmer
Nov 1, 2005
120
GB
I have a class called user

within the accessors of this class I have validation to ensure the format of the data is correct.

In my web UI i pass data from the web controls to these accessors. If there is an error with the data I want to highlight the control. I am thinking of throwing an event in the accessor if an error occurs - this will contain an error message.

I want to map the message to the correct control. How should I do this?
 
How about having a property in the user class that defines which control has the problem. Then, in your page, you could use FindControl to get a reference to the control that you wish to highlight.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Sorry - you 've lost me!

Are you suggesting that the class should know about the UI????
 
No, I meant the other way around. If I read your post correctly (which I may not have as I don't really understand what you mean by "accessor") your page will know about the class therefore your page could read a property that belonged to the class (which in turn would have been set by this "accessor") and highlight the control that was named in this property.

Not sure if that makes sense?!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
user.username = txtUsername.text
user.password = txtPassword.text

If theres an error I want to highlight the correct control... without having to repeat the validation code within the page.

Is that clearer?
 
OK, so it's just a standard class that you have set up. As you have set up properties for "username" and "password" in your user class, I would just do what I suggested.

When one of these values is set (i.e. in the Set section of your class), if the format is not correct, set another property to equal the name of the TextBox that is incorrect. Then, once you have set your properties from the page, check that class to get the name of the TextBox and use FindControl to highlight it.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top