Question

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?

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top