1

My page is a registration page, where a user enters a username, e-mail address and password. Here is my code behind:

protected void Page_Load(object sender, EventArgs e)
{
}

protected void btnRegister_Click(object sender, EventArgs e)
{
    if (!Page.IsValid)
        return;
}

protected void cvEmail_ServerValidate(object source, ServerValidateEventArgs args)
{
    args.IsValid = false;
}

Here is my page:

<asp:ValidationSummary ID="vs" runat="server" />

<asp:TextBox ID="txtUsername" runat="server" />
<asp:TextBox ID="txtEmail" runat="server" />
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" />

<asp:Button ID="btnRegister" runat="server" OnClick="btnRegister_Click" />

<asp:CustomValidator ID="cvEmail" runat="server" ControlToValidate="txtEmail" 
    OnServerValidate="cvEmail_ServerValidate"
    ErrorMessage="Invalid Email" />

So the problem is that if custom validator fails, when the page reloads with my error message, my textboxes are empty. But the weird thing is that if I inspect the textbox elements in Firebug, the value of the input is set, it's just not showing up on the page for some reason.

I've tried setting EnableViewState to true on the textbox and on the page, and that didn't help.

Anyone know what I'm doing wrong?

Steven
  • 18,761
  • 70
  • 194
  • 296
  • 1
    I just tried the sample code on a new project with .NET 4.0 and did not have any problems. The values for user and email are visible on the client after validation failure. The password is cleared but that is expected because it's a security feature. – João Angelo Aug 20 '12 at 20:42
  • Yeah, I also tried this and it worked. Try again in a brand new page. – Hanlet Escaño Aug 20 '12 at 21:26

1 Answers1

1

Do you have JavaScript validation turned on? Or any other JavaScript touching these fields?

If you see it in the page markup, but it does not show up in the browser, something is changing them after the page loads. Probably Javascript.

This would also support the findings posted in the question comments that the same code works in another project (which doesn't share the same JavaScript on the page).

BenSwayne
  • 16,810
  • 3
  • 58
  • 75