【发布时间】:2014-07-23 16:14:35
【问题描述】:
我有一个网页,其中包含多个验证器和页面上的验证摘要。这些是在页面加载时设置的,因为它们只是普通表达式和必填字段之类的东西。
我还有一些其他情况,当用户填写文本框时,系统必须在保存时检查它是否有效。然后,我想在摘要中显示一条附加消息以及最初创建的验证器,以表明该条目无效。
我尝试了以下方法,但保存时没有显示任何内容。此方法在保存按钮单击开始时调用,应该在验证摘要中添加一条消息并返回 isvalid = false。
protected bool ValidProductCode()
{
bool lValid = false;
if (!String.IsNullOrEmpty(txtProductCode.Text))
{
try
{
using (SqlConnection conn = new SqlConnection(GetConnection.GetConnectionString()))
{
DataSet ds = new DataSet();
SqlCommand sqlComm = new SqlCommand("PL_ProductCodes_FillScreen", conn);
sqlComm.Parameters.AddWithValue("@SiteID", ddlSiteId.SelectedValue);
sqlComm.Parameters.AddWithValue("@ProductCode", txtProductCode.Text);
sqlComm.Parameters.AddWithValue("@IsOntext", 1);
sqlComm.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlComm;
da.Fill(ds);
if (ds.Tables[0].Rows.Count != 0)
{
lValid = true;
}
}
}
catch (SqlException ex)
{
ExceptionHandling.SQLException(ex, constPageID, constIsSiteSpecific);
}
}
CustomValidator err = new CustomValidator();
err.IsValid = false;
err.ErrorMessage = "The product code entered is invalid";
Page.Validators.Add(err);
return lValid;
}
【问题讨论】:
标签: c# asp.net validation webforms