Reputation: 4908
I have a few fields in a webforms and currently I'm not implementing any form of validation but I intend to do so.
Suppose I have the following UpdateParameters
in my SQLDataSource
:
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Date" Type="DateTime" />
<asp:Parameter Name="active" Type="Boolean" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
And a textbox for each of the fields. I tried, but couldn't find a built-in way to validate the TextBoxes
against the parameter type, so for example, the Date_TextBox
would validate that the input is in a DateTime
format. I know I can do custom validators with regexes and whatnot, but I feel there's a built-in, simple way of doing it. Any ideas?
Upvotes: 1
Views: 260
Reputation: 21365
Have you tried using the CompareValidator
??
You can specify the type like this:
<asp:TextBox runat="server" ID="txt" />
<asp:CompareValidator runat="server" ErrorMessage="The type is not a valid integer"
ControlToValidate="txt"
Operator="DataTypeCheck"
Type="Integer"
/>
<asp:Button Text="Test valdiation" runat="server" />
The available types are:
Upvotes: 1