Any data post back over HTTP is text, and most of ASP.NET controls expose their value as text as well. Any control whose value will be parsed then needs to be validated as being required and of the correct type. We can do so using the validation controls :
<asp:RequiredFieldValidator ID="valRequired" runat="server" ControlToValidate="" ErrorMessage="*" />
<asp:CompareValidator ID="valInteger" runat="server" ControlToValidate="" Operator="DataTypeCheck" Type="Integer" ErrorMessage="*" />
We can also use the validation controls to make sure a value was chosen from a DropDownList, other than the prompt item with an associated value of zero :
<asp:CompareValidator ID="valNonZero" runat="server" ControlToValidate="" Operator="NotEqual" Type="Integer" ValueToCompare="0" ErrorMessage="*" />
Wednesday, July 16, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment