A
andersoj
I have a page that has some required field validators created in the
aspx, and other validators created in the Page_Load event.
In IE, all validation works as expected. In Firefox, ASPX validators
work fine, but the validators created in the code-behind do not.
Am I adding the validators to the wrong control on the page? Right now
I'm finding the main form control and adding them to that. Adding to
Page.Validators didn't work.
ASPX validators:
<asp:ValidationSummary ID="vlSummary" Runat="server" ShowSummary="True"
DisplayMode="BulletList" HeaderText="Please correct the following
error(s):" />
<asp:RequiredFieldValidator ID="vrqFirstName" Runat="server"
ControlToValidate="txtFirstName" ErrorMessage="First Name is required"
Display="None" />
<asp:RequiredFieldValidator ID="vrqLastName" Runat="server"
ControlToValidate="txtLastName" ErrorMessage="Last Name is required"
Display="None" />
<asp:RequiredFieldValidator ID="vrqAddress" Runat="server"
ControlToValidate="txtAddress" ErrorMessage="Address is required"
Display="None" />
Code-behind (called from Page_Load method):
private void AddReqFieldValidator(string fld, string msg_fld)
{
System.Web.UI.WebControls.RequiredFieldValidator rfv = new
System.Web.UI.WebControls.RequiredFieldValidator();
rfv.ID = "vrq" + fld;
rfv.ControlToValidate = fld;
rfv.ErrorMessage = msg_fld + " is required";
rfv.Display = ValidatorDisplay.None;
rfv.EnableClientScript = true;
Page.FindControl("frmPage").Controls.Add(rfv);
}
aspx, and other validators created in the Page_Load event.
In IE, all validation works as expected. In Firefox, ASPX validators
work fine, but the validators created in the code-behind do not.
Am I adding the validators to the wrong control on the page? Right now
I'm finding the main form control and adding them to that. Adding to
Page.Validators didn't work.
ASPX validators:
<asp:ValidationSummary ID="vlSummary" Runat="server" ShowSummary="True"
DisplayMode="BulletList" HeaderText="Please correct the following
error(s):" />
<asp:RequiredFieldValidator ID="vrqFirstName" Runat="server"
ControlToValidate="txtFirstName" ErrorMessage="First Name is required"
Display="None" />
<asp:RequiredFieldValidator ID="vrqLastName" Runat="server"
ControlToValidate="txtLastName" ErrorMessage="Last Name is required"
Display="None" />
<asp:RequiredFieldValidator ID="vrqAddress" Runat="server"
ControlToValidate="txtAddress" ErrorMessage="Address is required"
Display="None" />
Code-behind (called from Page_Load method):
private void AddReqFieldValidator(string fld, string msg_fld)
{
System.Web.UI.WebControls.RequiredFieldValidator rfv = new
System.Web.UI.WebControls.RequiredFieldValidator();
rfv.ID = "vrq" + fld;
rfv.ControlToValidate = fld;
rfv.ErrorMessage = msg_fld + " is required";
rfv.Display = ValidatorDisplay.None;
rfv.EnableClientScript = true;
Page.FindControl("frmPage").Controls.Add(rfv);
}