have a pulldown with both AutoPostback set to true and a validator.
When I select an “invalid” value from the pulldown, the validator message
shows briefly, then a postback occurs and the errormessage is gone!
this is my code:
<asp:TextBox ID="SerialFrom_txt" runat="server" BackColor="White" BorderColor="#188F3E"
BorderStyle="Solid" BorderWidth="3px" Width="200px" OnTextChanged="SerialFrom_txt_TextChanged"
AutoPostBack="true"></asp:TextBox>
<asp:RegularExpressionValidator ID="SerialFrom_rv" runat="server" ValidationExpression="^[a-zA-Z]{2}[0-9]{7}$"
Text="error" ControlToValidate="SerialFrom_txt" />
and my behind code for post back is:
protected void SerialFrom_txt_TextChanged(object sender, EventArgs e)
{
if (string.Compare(RoleFrom_lbl.Text, SerialFrom_txt.Text) > 0)
{
Error_lbl.Text = "Serial From must be greater than " + RoleFrom_lbl.Text + "!";
SerialFrom_txt.BackColor = System.Drawing.Color.FromName("red");
SAVE_btn.Enabled = false;
}
else
{
Error_lbl.Text = "";
SerialFrom_txt.BackColor = System.Drawing.Color.FromName("white");
SAVE_btn.Enabled = true;
}
}
so please tell me what should I do?
Try adding CausesValidation=”true” to your Textbox, like so: