I have a DetailsView with first, last, and email fields. When Ilook in the sourc code they are BoundField tags. I was wonderinghow I can validate these. I know how to validate regular Textboxtags, but when I try to validate these, there's no ID for thevalidate control to select. I read that data bound fieldsautomatically validate before updating. However, when I submitempty fields for my boundfields, it gives a server error message ratherthan a nice user-friendly message. How do I fix this?
thanks!
One way to do it would be to wrap your insert methods in a try / catch scenario.
I typically hate to let exceptions dictate program flow, but your database is already doing validation, and will return an error when one exists.
Try
Insert command
Catch ex as exception.
If ex = "1001" Then
label1.text = "You tried to insert an invalid value"
End Try
There may be a better way.
Ok the bad news is you cant really validate boundfileds correctly unless you change your bound columns to be templatefields.
Remeber that when you change the bound field to a template field you need to validate the insertItemTemplate and the UpdateItemTemplate.
Cheers
Gregor
ok, thanks
No comments:
Post a Comment