0

I'm new to all this and trying to only allow numeric values to be entered into an existing TextBox in ASP.Net. I've got the code for this, but can't figure out where to put it in. If I do it like the below, it creates an additional box in the textbox (that works). How can I apply this limitation to the current textbox?

<asp:TableCell>
    <asp:TextBox ID="txtS2" runat="server" Width="95%" AutoPostBack="true" OnTextChanged="WerklikChanged"></asp:TextBox>
    <input type="text" onkeypress="filterDigits(event)"/>
</asp:TableCell>

Update:

I ended up using the below, which is not really what I wanted as it still only checks the field once I leave the field. I'll look into blocking the entry of letters completely at a later stage and post the answer here.

<asp:CompareValidator
ID="ProgrammaticID"
ControlToValidate="txtS2KoringA"
Type="Double"
Operator="DataTypeCheck"
ErrorMessage="Error Message"
Text=" Net nommers word toegelaat in die 'Werklik' velde"
ForeColor="Red"
BackColor="White"
SetFocusOnError="false"
Display="Dynamic"
runat="server"> 
</asp:CompareValidator>
ctcoder
  • 1
  • 3
  • Possible duplicate of [asp.net Textbox Textmode Number, allow numbers only](https://stackoverflow.com/questions/37880654/asp-net-textbox-textmode-number-allow-numbers-only) or [How to allow only integers in a textbox?](https://stackoverflow.com/questions/9732455/how-to-allow-only-integers-in-a-textbox) – Siva Gopal Jul 02 '17 at 13:01
  • Thanks Siva, however, the other question only checks the input when moving out of the cell and then clears it. I want it to ignore the input if the user tries to input a letter, just like the "input" section in my original post does. I just want it to apply that constraint to the current textbox and not create it's own. – ctcoder Jul 02 '17 at 13:16
  • Any client side functionality extension you need, try the jQuery/Javascript based solution but make sure you validate input on server side as well. – Siva Gopal Jul 02 '17 at 13:19
  • Possible duplicate of [asp.net Textbox Textmode Number, allow numbers only](https://stackoverflow.com/questions/37880654/asp-net-textbox-textmode-number-allow-numbers-only) – VDWWD Jul 02 '17 at 14:39

0 Answers0