How to use Ajax MaskedEditExtender and MaskedEditValidator for Currency

Some-days back I was working on a text-box control which accepts only currency value.

I was already using AJAX Control Toolkit, so planned to use the existing control's which toolkit offers.

Those controls were MaskedEditExtender combined with MaskedEditValidator which was very powerful.

We can easily avoid JavaScript or JQuery or any third party controls.

But using these controls for currency purpose was bit hard, to put all logic together and make it workable.

I came up with this solution. I like to share those info here. Hope that helps others also. 

<asp:TextBox id="txtCurrency" Width="100px" runat="server" TabIndex="11">

</asp:TextBox>
<
cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" 

Enabled="True" TargetControlID="txtCurrency"

MaskType="Number"
Mask
="999\,999\,999.99"
ClearMaskOnLostFocus
="true"
InputDirection
="RightToLeft"
AcceptNegative
="None"
MessageValidatorTip
="true">
</
cc1:MaskedEditExtender> 

<cc1:MaskedEditValidator

ID="MaskedEditValidator1"
runat
="server"
ControlToValidate
="Amount"
ControlExtender
="MaskedEditExtender1"
Display
="Dynamic"
IsValidEmpty
="False"
EmptyValueMessage
="Amount is required"
InvalidValueMessage
="Amount is invalid"
MinimumValue
="0.01"
MinimumValueMessage
="Amount is too small"
MaximumValueMessage
="Amount is too large" />

You can include MaximumValue property if required.


Ebook Download
View all
Learn
View all