Tuesday, July 28, 2009

How can I create a textbox in ASP.net 2.0 nadthat would only accept numeric values?

I am trying to create a textbox in Visual Studio 2005 website (asp.net 2.0 and C#) that will only accept numeric values. The textbox must not even allow the alphabetical characters to be displayed. Error messages alone are not enough.

How can I create a textbox in ASP.net 2.0 nadthat would only accept numeric values?
The textbox doesn't have that ability on it's own. There are a couple numeric only textbox addin tools available online. Here's a link to a developer who uses the onKeyPress event to only allow numeric entry. The code is downloadable if you register with the site





http://www.c-sharpcorner.com/UploadFile/...





hope that helps
Reply:One way is to use a RangeValidator control as follows. You can omit the Required Field validator:


%26lt;asp:TextBox ID ="txtTest" runat ="server" /%26gt;


%26lt;asp:RangeValidator ID="ValidateTest" runat ="server" ControlToValidate ="txtTest"


Type ="Integer" ErrorMessage ="Input should be integer" MaximumValue ="1000" MinimumValue ="0" Display ="dynamic" /%26gt;


%26lt;asp:RequiredFieldValidator ID ="rqv" runat ="server" ControlToValidate ="txtTest" ErrorMessage="Text Cannot be blank" Display ="dynamic" /%26gt;


%26lt;asp:Button ID="btn" runat="server" Text="button" /%26gt;

aster

No comments:

Post a Comment