1

So I want to include a mask to my textbox. I have researched for different options and I have tried all of them but none seem to work. Im using VS2013 and C# and I want to be able to use textbox.text on my code too.

I have something like this:

 <script type="text/javascript" src="/js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="/js/jquery.maskedinput.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#TxtDOB").mask("999-999-9999");
        });
    </script>

asp:TextBox ID="TxtDOB" runat="server" CssClass="textbox1" Width="130px" />

TextBox won't recognize the mask.

7
  • can you make a jsfiddle? Commented Oct 30, 2015 at 17:45
  • Is the textbox added to the page dynamically (after the initial page load)? Commented Oct 30, 2015 at 17:51
  • Correct. It is a field that gets populated first and it also serves as an adding new dob Commented Oct 30, 2015 at 18:15
  • You'll have to initialize the mask plugin after the textbox is loaded. Right now it attempts to initialize to a non-existent element. Commented Oct 30, 2015 at 18:54
  • Jasen... I didn't it matter but I have tried already and it won't work Commented Oct 30, 2015 at 19:08

1 Answer 1

1

I'm a bit late to the party, but adding ClientIDMode="static" should fix the issue here. By default, .Net will convert the ID ("TxtDOB" in this case) to something other than what you set it to. Adding ClientIDMode="static" tells .Net not to change the ID and make it available as-is on the client-side.

<asp:TextBox ID="TxtDOB" runat="server" ClientIDMode="static" CssClass="textbox1" Width="130px" /> 
Sign up to request clarification or add additional context in comments.

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.