I'm validating a form using a CustomValidator so I can colour the background of the textbox.
The code behind for the CustomValidator doesn't get called when I click the form's linkbutton. However, when I remove PostBackUrl="orderconfirm.aspx" the code does get called and works fine.
aspx page:
<asp:TextBox ID="txtBillingLastName" Name="txtBillingLastName" runat="server">/asp:TextBox>
<asp:CustomValidator
ID="CustomValidatorLN" runat="server"
ControlToValidate="txtBillingLastName"
OnServerValidate="CustomValidatorLN_ServerValidate"
ValidateEmptyText="True">
</asp:CustomValidator>
<asp:LinkButton
ID="OrderButton" runat="server"
PostBackUrl="orderconfirm.aspx"
onclick="OrderButton_Click">
</asp:LinkButton>
code behind:
protected void CustomValidatorLN_ServerValidate(object sender, ServerValidateEventArgs args)
{
bool is_valid = txtBillingLastName.Text != "";
txtBillingLastName.BackColor = is_valid ? System.Drawing.Color.White : System.Drawing.Color.LightPink;
args.IsValid = is_valid;
}
I'm pretty new to .net/c# and to be honest I didn't get the answers to similar problems searched for on here.
Any help would be greatly appreciated.