I’m not sure exactly what you’re looking for. Are you looking to run a function that only shows certain (numerical) characters when a user is typing into a textbox? … or are you just looking for a general way to convert a number to two decimal places?
Doing this as people type becomes very tricky, due to cross-browser differences in handling key events. For a good run-down of the problems, see detecting keystrokes
So instead of doing it on a keystroke basis, it’s commonly more stable to do it after the field has been filled in, or when the form is submitted.
And here is the script that updates the field when you move out of the field. The script that is placed just before the </body> tag.
var form = document.getElementById('someForm');
form.elements.amount.onblur = dollarHandler;
function dollarHandler() {
var number = Number(this.value) || 0;
this.value = number.toFixed(2);
}
Note: ‘someForm’ is the identifier of the form, and form.elements.amount is the name attribute of the form field.
I have no experience with telerik controls in a .asax web control file, but no doubt someone in the .NET forum will be able to piece that together for you.
Telerick controls and asax files are simply .net files, with enhanced functionality.
The only problem here, is they dont have a webform, which normally pages do have, apart from that, it works the same way, cos the above javascript and other javascript funtions work ok.
Yeah, maybe you should throw more light into what you want to achieve, if what you are working with has no form tags, then where’s the textbox going to be exactly…
We are working on a project, that uses telerik controls. And they have the web controls *.asax files in the webforms *.aspx files, which dont have the <form><\form> tags.
I was surprised initially, but was told thats how telerik controls work.