Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Input > Problem with RadMaskedTextBox
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Answered Problem with RadMaskedTextBox

Feed from this thread
  • Cansin avatar

    Posted on Jun 15, 2011 (permalink)

    Hello Guys,

    I've got a small problem with radmaskedtextbox :( When users try to enter a value in to RMTB(radmaskedtextbox) (______) i  want from rmtb to add "0" automatically in front of entered value (7898__) like 007898 not like 789800. My code is putting 0 s at the end of the entered value. I changed the NumericRangeAlign Left or Right and also DisplayFormatPosition but that didn't give me anything.   
    Waiting your kind solutions...

    By the way i'm using telerik version: "2011.1.519.35"
    Thanks
    Cansin

    here is my code:

     

    <telerik:RadMaskedTextBox  
    NumericRangeAlign="Right" 
    HideOnBlur="true"
    EmptyMessage=""
    style="TEXT-ALIGN:right" 
    runat="server" 
    id="RadMaskedTextBox" 
    Mask="######" 
    DisplayMask="######" 
    DisplayPromptChar="0">   
    </telerik:RadMaskedTextBox>

     

  • Answer Martin Martin admin's avatar

    Posted on Jun 20, 2011 (permalink)

    Hello Cansin,

    You can use the ValueChanged client side event to achieve the desired functionality. Here is a sample page demonstrating it:

    <%@ Page Language="C#" %>
     
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <head id="Head1" runat="server">
    </head>
    <body>
        <form id="mainForm" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        </asp:ScriptManager>
        <script type="text/javascript">
     
            function ValueChanged(sender, args)
            {
                var oldValue = args.get_newValue();
                var match = oldValue.match(/_+$/);
                var newValue = [];
                if (match!== null && match.length === 1)
                {
                    for (var i = 0; i < match[0].length; i++)
                    {
                        newValue.push("0");
                    }
                    newValue.push(oldValue.slice(0, oldValue.lastIndexOf(match[0])));
                    sender.set_value(newValue.join(""));
                }
            }
         
        </script>
        <telerik:RadMaskedTextBox NumericRangeAlign="Right" HideOnBlur="true" EmptyMessage=""
            Style="text-align: right" runat="server" ID="RadMaskedTextBox" Mask="######"
            DisplayMask="######" DisplayPromptChar="0">
            <ClientEvents OnValueChanged="ValueChanged" />
        </telerik:RadMaskedTextBox>
        </form>
    </body>
    </html>

    I hope this helps.

    All the best,
    Martin
    the Telerik team

    Consider using RadControls for ASP.NET AJAX (built on top of the ASP.NET AJAX framework) as a replacement for the Telerik ASP.NET Classic controls, See the product support lifecycle here.

  • Cansin avatar

    Posted on Jun 21, 2011 (permalink)

    Hello Martin,

    Thank you for your kind interest. I tried your code and working perfectly:) Thank you again.

    Cansin

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Input > Problem with RadMaskedTextBox