I've created an editor templace in an mvc app, and I want to restrict the input of each text box in the template to only numbers.
At render time, the template my be rendered multiple times on the page because the view could have multiple properties that are of type phone number, so the actual IDs of the text boxes will get unique names. What is the best way for me to add some jquery code to the template, reducing duplication of code, and being able to handle the issue of the ID's being dynamically generated by the mvc framework?
Below is my template:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PhoneNumber>" %>
<span>
(<%= Html.TextBox("AreaCode", (Model == null) ? "" : Model.AreaCode, new { size = 3, maxlength = 3, style = "width:25px" })%>)
<%= Html.TextBox("Prefix", (Model == null) ? "" : Model.Prefix, new { size = 3, maxlength = 3, style = "width:25px" })%>-
<%= Html.TextBox("Suffix", (Model == null) ? "" : Model.Suffix, new { size = 3, maxlength = 4, style = "width:35px" })%>
<%= Html.TextBox("Extension", (Model == null) ? "" : Model.Extension, new { size = 10, maxlength = 10, style = "width:55px" })%>
</span>