Search code examples
asp.net-mvcasp.net-mvc-2validationclient-sideasp.net-mvc-2-validation

client side validation in ascx files (user controls) for asp.net mvc


I have a logOn forn in ascx files and I render it as partial. How I can add a clinet side validation to this form, have any idea ?

My below code does not work

<%= Html.ValidationSummary(true, "Giriş başarısız oldu. Lütfen hataları düzeltip tekrar deneyin.") %>
    <% Html.EnableClientValidation(); %> 
    <% using (Html.BeginForm("LogOnProcess", "Account")) { %>
        <div>
            <fieldset>
                <legend>Hesap Bilgileri</legend>

                <div class="editor-label">
                    <%= Html.LabelFor(m => m.UserName) %>
                </div>
                <div class="editor-field">
                    <%= Html.TextBoxFor(m => m.UserName) %>
                    <%= Html.ValidationMessageFor(m => m.UserName) %>
                </div>

                <div class="editor-label">
                    <%= Html.LabelFor(m => m.Password) %>
                </div>
                <div class="editor-field">
                    <%= Html.PasswordFor(m => m.Password) %>
                    <%= Html.ValidationMessageFor(m => m.Password) %>
                </div>

                <div class="editor-label">
                    <%= Html.CheckBoxFor(m => m.RememberMe) %>
                    <%= Html.LabelFor(m => m.RememberMe) %>
                </div>

                <p>
                    <input type="submit" value="Giriş" />
                </p>
            </fieldset>
        </div>
    <% } %>

Solution

  • I had issues with the built in client side validation in some ascx pages. What I had to do was use the jQuery validation to achieve this. Check out this link:

    http://docs.jquery.com/Plugins/Validation