ASP.NET MVC Page - Viewstate for Confirm email field is getting erased on Registration Page if valid

Posted by Rita on Stack Overflow See other posts from Stack Overflow or by Rita
Published on 2010-04-26T18:27:21Z Indexed on 2010/04/26 18:33 UTC
Read the original article Hit count: 325

Filed under:
|

Hi

I have a Registaration page with the following fields Email, Confirm Email, Password and Confrim Password.

On Register Button click and post the model to the server, the Model validates and if that Email is already Registered, it displays the Validation Error Message "User already Exists. Please Login or Register with a different email ID".

While we are displaying this validation error message, I am loosing the value of "Confirm Email" field. So that the user has to reenter again and I want to avoid this.

Here I don't have confirm_Email field in my Model.

Is there something special that has to be done to remain Confirm Email value on the Page even in case of Validation failure?

Appreciate your responses.

Here is my Code:

<% using (Html.BeginForm()) {%>
    <%= Html.ValidationSummary(false) %>

    <fieldset>
    <div class="cssform">

        <p>
            <%= Html.LabelFor(model => model.Email)%><em>*</em>
            <%= Html.TextBoxFor(model => model.Email, new { @class = "required email" })%>
            <%= Html.ValidationMessageFor(model => model.Email)%>
        </p>

        <p>
            <%= Html.Label("Confirm email")%><em>*</em>
            <%= Html.TextBox("confirm_email")%>
            <%= Html.ValidationMessage("confirm_email") %>
        </p>

        <p>
            <%= Html.Label("Password")%><em>*</em>
            <%= Html.Password("Password", null, new { @class = "required" })%>
            <%= Html.ValidationMessage("Password")%><br />
            (Note: Password should be minimum 6 characters)
        </p>

        <p>
            <%= Html.Label("Confirm Password")%><em>*</em>
            <%= Html.Password("confirm_password")%>
            <%= Html.ValidationMessage("confirm_password") %>
        </p><hr />

        <p>Note: Confirmation email will be sent to the email address listed above.</p>
    </fieldset>

<% } %>

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-2