views:

56

answers:

1

Hello, I have a displayFormat pattern "$###,###,###;-$###,###,###;#"( it can be different too) and I want to reformat the value in the AspxTextbox after deleting the ',' on GotFocus and LostFocus events by calling the following JavaScript function :

function TextBoxFormat(ctrl, e, displayFormat, charactersToRemove) {
var value = ctrl.GetValue();
var i;

if (value != null && charactersToRemove != null) {
    for (i = 0; i < charactersToRemove.length; i++)
        value = value.replace(charactersToRemove[i], '');

    ctrl.SetValue(ASPxFormatter.Format('{0:' + displayFormat + '}', 
         parseInt(value)));
}

I have tried to use ASPxFormatter but it is an internal class that is not indented to be used in a user project.Using String.Format('{0:' + displayFormat + '}', parseInt(value))); didn't work too , it threw an exception since String.format doesn't accept this format of pattern, Can you please provide a way to reformat my string to any pattern I want not only the one I recite since ? I highly appreciate your support....

Alaa

Thanks

A: 

The MaskedEdit in the ajax control toolkit looks very much like what you want to do. If you don't want to use the pre-built controls, you can get the javascript source in one of the download packages.

lincolnk
Thanks for you quick answer,it seems a good idea, I couldn't get the javascript source code, would you provide it ot me ?
Alaa Osta
http://ajaxcontroltoolkit.codeplex.com/releases/view/43475 this page gives the download options. the javascript source should be available in one of those- probably AjaxControlToolkit.Source.zip ?
lincolnk
That is too much complicated for a simple task, it should be something in JavaScript to get the value and reformat it according to the given pattern
Alaa Osta