<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <script type="text/javascript">
        function maskedLoad(sender, args) {

            //indicates the number of visible digits from the end of the value

            sender._visibleDigits = 4;



            //cache the original get_displayValue method and overwrite it

            sender._originalGetDisplayValue = sender.get_displayValue;

            sender.get_displayValue = Function.createDelegate(sender, function () {

                var value = this.get_valueWithPrompt();

                if (!isNaN(parseInt(value)))    //if value can be parsed into a number
                {

                    //cache the original get_valueWithPrompt method and overwrite it

                    //we need this because the original get_displayValue uses this method

                    //to retrieve the value to be displayed

                    this._originalGetValueWithPrompt = this.get_valueWithPrompt;

                    this.get_valueWithPrompt = Function.createDelegate(this, function () {

                        var original = this._originalGetValueWithPrompt.call(this);



                        if (!isNaN(parseInt(original))) {

                            //if value can be parsed in to a number and it has

                            //more digits than the visible digits number, we 

                            //want to return the last N digits, where N = this._visibleDigits

                            if (original.length > this._visibleDigits) {

                                original = original.substr(original.length - this._visibleDigits);

                            }

                        }



                        return original;

                    });



                    //call the original get_displayValue with the overwritten get_valueWithPrompt.

                    var displayValue = this._originalGetDisplayValue.call(this);

                    //restore the original get_valueWithPrompt method

                    this.get_valueWithPrompt = this._originalGetValueWithPrompt;



                    return displayValue;

                }



                //if original value with prompt cannot be parsed into a number,

                //fall back to the original get_displayValue method

                return this._originalGetDisplayValue.call(this);

            });

        }
    </script>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <telerik:RadMaskedTextBox ID="RadMaskedTextBox1" runat="server" Mask="##########"
        DisplayMask="******####">
        <ClientEvents OnLoad="maskedLoad" />
    </telerik:RadMaskedTextBox>
    <asp:Button ID="Button1" runat="server" Text="Get the value on the server" onclick="Button1_Click" />
    <div>
    </div>
    </form>
</body>
</html>
