Hi,
I am using detailsView to insert data into a table. I have converted the columns into templates. Before I insert the record, I want to validate the data in the columns. What is the best approach to do this?
Thanks, sandy
Add validation control in the TemplateField.
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ProductName") %>'></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate = "TextBox1" ErrorMessage="RequiredFieldValidator">
</asp:RequiredFieldValidator>
</EditItemTemplate>
Does this mean that in order toperform validation on any standard edit-mode control (i.e. textbox),we'll basically have to convert each into a template?
If this is indeed the way to do it, it seems like most of the "ease"goes away with what seems to be "forgotten" must-have's - re: we allknow the issues of unvalidated input, so why would default inputcontrols not have an "easy" validation scheme? or not provide the sameintuitive process with other controls (being validated by validationcontrols)?
Yes, you can do this by catching the event and writing anything tovalidate/filter the input, but just the same, it seems to go againstthe grain of validation controls...
Sophia's solution works fine. For standard items like textbox you don't have concept of templates and you can directly use validation controls on them. However for gridview, detailsview or formview we need to convert their items to templates in order to apply validation controls on them.
Regards,
sandy
No comments:
Post a Comment