views:

614

answers:

1

Hi,

If my header/footer are in the master page, and my .js files are referenced in the master page, how can I add jQuery validation on my login page?

If there is an error detected, how will I modify the .js file to display the appropriate error message?

+1  A: 

Have you looked at the jquery validation plugin? The plugin handles a lot of different validation tasks automatically -- i.e., you might be able to get away with doing:

$(document).ready( function { $(form).validate(); } );

an annotating your text fields with the appropriate class attributes. You should be able to just reference the validation library on your view page and add the document ready function there as well inside a script tag.

<asp:Content runat="server" ID="viewcContent" ContentID="masterContent">
   <script type="text/javascript" src="..path_to/jquery.validate.js">
   </script>
   <script type="text/javascript">
       $(document).ready( function { $(form).validate(); } );
   </script>
   <% using (Html.BeginForm()) { %>

     ... form implementation...

      <input type="text" id="username" name="username" class="required" />


   <% } %>
</asp:Content>
tvanfosson