0

I'm trying to use jquery meio mask with asp.net page.

it is working ok with input text box but I do not know how to use it it with asp.net text box.

when I run my code the html text box is only working.

please advice?

http://www.meiocodigo.com/projects/meiomask/

here is my code: ..........................................

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script src="../js/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../js/jquery.meio.mask.js" type="text/javascript"></script>

    <script type="text/javascript" charset="utf-8">
        $(document).ready(function() {
            $.mask.masks = $.extend($.mask.masks, {
            htmlPhone: { mask: '(999)999-9999' }

            });
            $('input:text').setMask();
        });


        $(document).ready(function() {
            $.mask.masks = $.extend($.mask.masks, {
                aspPhone: { mask: '(999)999-9999' }

            });
            $('asp:TextBox').setMask();
        });


    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">


     <p><label for="phone">ASP Phone #</label><br /><asp:TextBox ID="aspPhone" runat="server"></asp:TextBox></p>

     <p><label for="phone">HTML Phone #</label><br /><input type="text" name="htmlPhone" value="" id="phone" alt="phone" /></p>




</asp:Content>

4 Answers 4

1

Since asp:TextBox tag is not available to jQuery (if you were to examine your page source in Firefox or IE you wouldn't see it), what you will want to do is either give the TextBox a css class that you could use with jQuery or supply jQuery with a valid ClientID for the textbox. I would choose the css route, in which case you can change the TextBox declaration to something like

<asp:TextBox ID="aspPhone" runat="server" CSSClass="phoneNumber" />

and your jQuery code to

$('.phoneNumber').setMask();
Sign up to request clarification or add additional context in comments.

3 Comments

I added CSSClass="phoneNumber" and I update my script but notthing happen when I run the code there is no mask for the asp text box. any advice?? here is my script.................................................. $(document).ready(function() { $.mask.masks = $.extend($.mask.masks, { aspPhone: { mask: '(999)999-9999' } }); $('.phoneNumber').setMask(); });
looking back at your code the first part $('input:text').setMask() alone should be sufficient since asp:TextBox will render as <input type="text" />. What happens if you remove the second $(document).read() function (which, btw, there's no need to have 2 functions specified)
I removed the second one and put back $('input:text').setMask() but still nothing happen.. any advice, Regards,
1

hello you missed the main cause dude. use alt attribute in any control. masking will work according to it. whether in asp or html. like: <asp:TextBox ID="aspPhone" runat="server" alt="phone-us"></asp:TextBox>

Thanks.

Comments

0

An ASP.NET textbox created with <asp:TextBox> is still going to render as <input type="text" ...>.

Leave your jQuery as it was:

$('input:text').setMask();

Or if you really want to only apply it to that one field, you can use its ID like this:

$('#<%= aspPhone.ClientID %>').setMask();

1 Comment

Thank you for trying helping me. I tried both ways but nothing work there is no mask any advice?
0

Since the meioMask plugin works with the "alt" HTML attribute, you have to set it in order for it to work. This would do the trick:

$('#<%= aspPhone.ClientID %>').attr('alt', 'phone').setMask();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.