具有 AutoPostback 设置为 true 和验证器的下拉。当我从下拉列表中选择“无效”值时,验证器消息会短暂显示,然后发生回发并且错误消息消失了!这是我的代码:
<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" />
我的回发代码是:
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;
}
}
所以请告诉我该怎么办?