We help IT Professionals succeed at work.

How am I going to do with the TextBox validation in my WebForm?

runbird
runbird asked
on
Hi,

I am doing the Webform development. And I am using ASP.NET in VB & .NET Framework 1.1
May I know how to do the number validation on my TextBox control?

Thanks & Regards,
Chung Ee
Comment
Watch Question

Commented:
If the textbox MUST have a value, you will need a required field validator and a compare validator:

<asp:RequiredFieldValidator ID="MyRequiredFieldValidator" runat="server" ControlToValidate="MyTextBoxID" ErrorMessage="Please specify a value"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="MyCompareValidator" runat="server" ControlToValidate="MyTextBoxID" ErrorMessage="The value entered is not of type XYZ" Operator="DataTypeCheck" Type="Integer"></asp:CompareValidator>

You can also use double instead of Integer if you require a decimal value.

Commented:
Note that if you do not need the textbox to always contain a value, then you don't need the RequiredFieldValidator.
Forced accept.

Computer101
EE Admin

Explore More ContentExplore courses, solutions, and other research materials related to this topic.