1

I have an ASP.NET web form, and I'm using the masked input plugin from http://digitalbush.com/projects/masked-input-plugin, which seems to be a pretty popular plugin. It works very well, but I'm having an issue when attempting to pre-populate a value in a textbox using the masking.

In my document.ready, Im performing:

$("#txtPrimaryPhone").mask("(999) 999-9999 ?x9999");

In my codebehind I set my text property like so:

txtPrimaryPhone.Text = "1234567890";

When my page loads, my textbox is empty. Has anyone run into similar issues, or can anyone offer any suggestions? Thanks!

2 Answers 2

1

Here's the solution :

Instead of

$("#txtPrimaryPhone").mask("(999) 999-9999 ?x9999");

Try this

 $.each($('#txtPrimaryPhone'), function (iEmt, emt) {
            $(emt).mask("(999) 999-9999 ?x9999").val($(emt).attr("value"));
        });

it works for me :)

Sign up to request clarification or add additional context in comments.

Comments

0

If I’m correct, the jQuery mask is applied once you load your page, then your txtPrimaryPhone.Text is set server side. I have two theories.

One: 1234567890 is not accepted by the mask because it is not in the right format. Right format should be something like txtPrimaryPhone.Text = “(999) 999-9999 x99999”;.

Two: The mask works as a filter for user input but does not accept the server side value for txtPrimaryPhone. It’s a little hard to find out without a sample we can debug or edit.

1 Comment

Thanks Yushell, I tried pre-formatting the value before sending it to the screen, but it still didn't show. Thanks for the insight though, appreciate it..

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.