I have an ASP.net TextBox with Number TextMode, I'm wondering if I could use Up and Down key to increment and decrement the value, and set the min and max value in easy way. Some suggestions?
Setting the TextMode to Number uses the browser's HTML5 understanding of HTML input attributes. (It assumes you are using framework 4.5 or above.)
Modern browsers put an up/down arrow in the resulting HTML input that lets you increment or decrement the value you've entered. This implementation is under the browser's control, not yours. And most browsers do, in fact, respond to the up and down keys
for triggering this arrow function, as long as the textbox has focus. (Try it out.)
So the only thing you are left with is setting a min and max value. Use a RangeValidator. This won't prevent people from typing, arrowing, or up/down key entering a value that is out of range, but it will display an error message until they correct it,
and the value will not be valid for submitting the form.
<asp:TextBox ID="TextBox1" runat="server" TextMode="Number"></asp:TextBox>
<asp:Rangevalidator ID="Rangevalidator1" errormessage="Please enter value between 10-55." forecolor="Red" controltovalidate="TextBox1" minimumvalue="10" maximumvalue="55" runat="server" Type="Integer">
</asp:Rangevalidator>
I have an ASP.net TextBox with Number TextMode, I'm wondering if I could use Up and Down key to increment and decrement the value, and set the min and max value in easy way. Some suggestions?
Why don't use the NumericUpDown in the Ajax Control Toolkit?
Unlike the input type="number", the NumericUpDown is NOT browser-dependent and can be used in most major browsers (including IE) with same appearance. It has the Maximum and Minimum properties you require.
Member
1 Points
7 Posts
Can I use Up and Down arrow key in a ASP.net textbox? And set min and max value?
Feb 19, 2021 04:43 PM|MrDog49|LINK
I have an ASP.net TextBox with Number TextMode, I'm wondering if I could use Up and Down key to increment and decrement the value, and set the min and max value in easy way. Some suggestions?
Contributor
5961 Points
2466 Posts
Re: Can I use Up and Down arrow key in a ASP.net textbox? And set min and max value?
Feb 21, 2021 07:43 PM|KathyW|LINK
Setting the TextMode to Number uses the browser's HTML5 understanding of HTML input attributes. (It assumes you are using framework 4.5 or above.)
Modern browsers put an up/down arrow in the resulting HTML input that lets you increment or decrement the value you've entered. This implementation is under the browser's control, not yours. And most browsers do, in fact, respond to the up and down keys for triggering this arrow function, as long as the textbox has focus. (Try it out.)
So the only thing you are left with is setting a min and max value. Use a RangeValidator. This won't prevent people from typing, arrowing, or up/down key entering a value that is out of range, but it will display an error message until they correct it, and the value will not be valid for submitting the form.
Member
330 Points
235 Posts
Re: Can I use Up and Down arrow key in a ASP.net textbox? And set min and max value?
Feb 22, 2021 01:30 AM|SurferOnWww|LINK
Why don't use the NumericUpDown in the Ajax Control Toolkit?
NumericUpDown Demonstration
https://ajaxcontroltoolkit.devexpress.com/NumericUpDown/NumericUpDown.aspx
Unlike the input type="number", the NumericUpDown is NOT browser-dependent and can be used in most major browsers (including IE) with same appearance. It has the Maximum and Minimum properties you require.