Customer Validation ASP.Net C#
I am having the same problem as someone else in this forum. My validation control is not firing...and not sure where I have gone wrong. Could someone please take a look and let me know what obvious error I have here...thanks
I have set up a customer validator in my aspx page using the following:
<asp:TextBox ID="EmployeeNumber2TextBox" runat="server"
Text='<%# Bind("EmployeeNumber") %>'Visible='<%# AllowEmployeeNumberEdit() %>' />
<asp:CustomValidator ID="ValidateEmpNumber" runat="server"
onservervalidate="ValidateEmpNumber_ServerValidate"
controltovalidate="EmployeeNumber2TextBox"
ErrorMessage="You Must Enter an Employee Number" Text="*" />
and the code behind:
protected void ValidateEmpNumber_ServerValidate(object sender, System.Web.UI.WebControls.Serv开发者_JS百科erValidateEventArgs e)
{
int SiteCompanyID = System.Convert.ToInt32(Session["SiteCompanyID"]);
SiteCompanyBLL SiteCompany = new SiteCompanyBLL();
SiteCompanyDAL.SiteCompanyRow ScRow = SiteCompany.GetCompanyByID(SiteCompanyID);
bool AutoGenerate = ScRow.AutoGenNumber; // result returning true or false
if (AutoGenerate == false)
{
if (e.Value.Length == 0)
e.IsValid = false;
else
e.IsValid = false;
}
}
Is the validator in sync with the control that is doing the submit/postback? Also, there is no condition that allows it to be true.
How do you know it isn't firing?
Did you try making the OnServerValidate and ControlToValidate with the first letter of each word uppercase? Those properties may be case sensitive.
I was able to run a cutdown version of your code on my system.
Are you sure your Web.config is set to compile debug?:
<compilation debug="true">
加载中,请稍侯......
精彩评论