This is a pretty straight-forward question, which I'm sure has a very easy answer that I'm just missing.
I have a textbox with an up/down control, with a minimum of 0 and maximum of 30. Currently, you can also put the cursor into the textbox and type in a value, so I also put in a FilteredTextBoxExtender that will ensure that only numbers can be entered.
It works exactly as advertised, except that it allows the user to enter number less than 0 and more than 30 if they put the cursor into the textbox and type it in.
Is there an easy way to keep the functionality that allows the user to manually edit the box, but ensure that if you type in a number like "200", that it resets it to 30?
I'm hoping there's a pre-existing, built-in solution, without me having to manually add some javascript code.
Plan B:
I'd rather not have to disable the textbox from user input, but if the above isn't possible, how do I do that and still maintain the up/down functionality? (The samples on the AJAX site work this way, but the setting to disable manual entry must be burried
somewhere in the code, because I did a quick scan and couldn't find it.)
I gave it a try, and it does work client-side, but it still isn't what I'm after unfortunately. :(
This would allow me to post an error message to the user, but instead I just want to automatically reset the textbox value (to 30 if they entered in a value over 30 - entering in a number less than 0 is already impossible since the textbox is already restricted
to numbers only, and the negative symbol isn't a number).
This means, back to the original question. Any easy way to either restrict the user from entering in numbers over 30? (Even if it lets them type in a number like 200, but then as soon as they pull the focus out of the textbox it snaps back to 30.)
Sounds like a CustomValidator would work for you. If you dont care about displaying any messages, then you can write some farily simple javascript onblur of the textbox, which would check if the value is > 30, and if so set it to 30. That code would not
be very hard to do, if you are somewhat familiar with JS.
Hmm, that technically would work, but I was looking for something that doesn't require that I write up any custom JavaScript code. : /
So, on to Plan B. Does anyone know how to disable a Textbox so that it seems enabled (and numericupdownextenders will still work on it), but a user cannot highlight and change the text? The NumericUpDownExtender example given on the AJAX site does this in
a couple of the samples, but I can't find where that option is being turned off/on. URL here: http://www.ajaxcontroltoolkit.com/NumericUpDown/NumericUpDown.aspx
The "June" and "500" examples show the "manual entry disabled" fuctionality I'd like to know how to do.
Aania
Member
8 Points
41 Posts
AJAX NumericUpDownExtender - Disable Manual Entry / Validation
Feb 27, 2010 01:08 PM|LINK
Hi there,
This is a pretty straight-forward question, which I'm sure has a very easy answer that I'm just missing.
I have a textbox with an up/down control, with a minimum of 0 and maximum of 30. Currently, you can also put the cursor into the textbox and type in a value, so I also put in a FilteredTextBoxExtender that will ensure that only numbers can be entered.
It works exactly as advertised, except that it allows the user to enter number less than 0 and more than 30 if they put the cursor into the textbox and type it in.
Is there an easy way to keep the functionality that allows the user to manually edit the box, but ensure that if you type in a number like "200", that it resets it to 30?
I'm hoping there's a pre-existing, built-in solution, without me having to manually add some javascript code.
Plan B:
I'd rather not have to disable the textbox from user input, but if the above isn't possible, how do I do that and still maintain the up/down functionality? (The samples on the AJAX site work this way, but the setting to disable manual entry must be burried somewhere in the code, because I did a quick scan and couldn't find it.)
Thanks,
Aania
MetalAsp.Net
All-Star
112162 Points
18252 Posts
Moderator
Re: AJAX NumericUpDownExtender - Disable Manual Entry / Validation
Feb 27, 2010 01:48 PM|LINK
Maybe you can try using a RangeValidator.
Aania
Member
8 Points
41 Posts
Re: AJAX NumericUpDownExtender - Disable Manual Entry / Validation
Feb 27, 2010 02:24 PM|LINK
Thanks for the suggestion, but if I understand correctly, RangeValidator only works server-side, does it not?
I'm looking for a real-time, clientside solution, similar to how the FilteredTextBoxExtender works client-side.
Aania
MetalAsp.Net
All-Star
112162 Points
18252 Posts
Moderator
Re: AJAX NumericUpDownExtender - Disable Manual Entry / Validation
Feb 27, 2010 02:46 PM|LINK
It works both sides. By default it has EnableClientScript set to true. You might give it a try...
Aania
Member
8 Points
41 Posts
Re: AJAX NumericUpDownExtender - Disable Manual Entry / Validation
Feb 27, 2010 03:38 PM|LINK
Hey again,
I gave it a try, and it does work client-side, but it still isn't what I'm after unfortunately. :(
This would allow me to post an error message to the user, but instead I just want to automatically reset the textbox value (to 30 if they entered in a value over 30 - entering in a number less than 0 is already impossible since the textbox is already restricted to numbers only, and the negative symbol isn't a number).
This means, back to the original question. Any easy way to either restrict the user from entering in numbers over 30? (Even if it lets them type in a number like 200, but then as soon as they pull the focus out of the textbox it snaps back to 30.)
Thanks,
Aania
MetalAsp.Net
All-Star
112162 Points
18252 Posts
Moderator
Re: AJAX NumericUpDownExtender - Disable Manual Entry / Validation
Feb 27, 2010 04:00 PM|LINK
Sounds like a CustomValidator would work for you. If you dont care about displaying any messages, then you can write some farily simple javascript onblur of the textbox, which would check if the value is > 30, and if so set it to 30. That code would not be very hard to do, if you are somewhat familiar with JS.
Aania
Member
8 Points
41 Posts
Re: AJAX NumericUpDownExtender - Disable Manual Entry / Validation
Feb 27, 2010 04:52 PM|LINK
Hmm, that technically would work, but I was looking for something that doesn't require that I write up any custom JavaScript code. : /
So, on to Plan B. Does anyone know how to disable a Textbox so that it seems enabled (and numericupdownextenders will still work on it), but a user cannot highlight and change the text? The NumericUpDownExtender example given on the AJAX site does this in a couple of the samples, but I can't find where that option is being turned off/on. URL here: http://www.ajaxcontroltoolkit.com/NumericUpDown/NumericUpDown.aspx
The "June" and "500" examples show the "manual entry disabled" fuctionality I'd like to know how to do.
Thanks,
Aania