Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I will tell u one example! Text box which accepts only numbers (characters will not be displayed)! In below code is available!

Code for Ajax(java script) :

JavaScript
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


i just download "AjaxControlToolkit.dll" and just added reference for that toolkit !

And

JavaScript
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" FilterMode="ValidChars" runat="server"
                TargetControlID="txtSun1N" ValidChars="1234567890.">
               </cc1:FilteredTextBoxExtender>


this is the way to text box accepting numbers only! If we enter any characters that text box will not be displayed in that text box.. Just try it's working !!

Like that if we enter any other number(above 24) means 25,26,3234534.. can't be display, When we tried to enter any other number that number can't be displayed..I need that!!

Can any one help me!! .
Posted
Updated 18-Dec-11 18:25pm
v3

y using ajax for this

just use asp regular expression validator to take only 1 to 24.

OR

simply use asp range validator to take numbers with min and max value.

OR

use 'ajaxToolkit:MaskedEditValidator' rather then filter text box extender if you want to achieve the mask effect. you can set the mask as '99' and range from 1 to 24.
 
Share this answer
 
v2
Comments
[no name] 19-Dec-11 1:27am    
My actual requirement is explained above! I know that validations, Presuppose if i use regular expression validator if we insert the max number and min numbers that should be fine. But daily 24hr's then once we enter any other numbers that numbers will not be display on that text box!
[no name] 19-Dec-11 1:29am    
once we try to enter any other numbers that number will not be display !
u got my point right!
saxenaabhi6 19-Dec-11 1:35am    
use masked edit extender of ajax tool kit in that case.
There are two ways to achieve this.

Let me start with the wrong way you should avoid. Don't try to use the same idea as filtering the input. I could easily create some JavaScript to filter input the way allowing only 1 to 24 or 0 to 24, whatever you want, but it will highly confuse the user. Imagine the user enters 23 and wants to change it to 21. The user can delete '3' and enter '1'. But she/he might want to add '1' first to get '231' to delete '3' later. You filter will prevent it leaving the user without any reasonable feedback on what to do. Don't try to introduce too complex filtering!

Instead, if you really want to stay with text input, you can use combination of filtering of characters on input, which you already achieved quite well, with validation. Don't perform validation too early; do it only when the data input by the user is about to be used. Give a user clear feedback on the valid input, such as "The value of {0} must be {1} to {2}", something like that.

I would use much simpler approach though. If you expect only 24 valid values or so, I would simply uses a combo box with all values pre-entered. The user will only select one of them. See http://www.asp.net/web-forms/tutorials/ajax-control-toolkit/combobox/how-do-i-use-the-combobox-control-cs[^].

—SA
 
Share this answer
 
I think using MaskedEditExtender and MaskedEditValidator together will solve your problem.

Have a look at here:
http://www.asp.net/ajaxlibrary/HOW%20TO%20Use%20the%20MaskedEdit%20Control.ashx[^]

and here :
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx[^]

Hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900