Problem: I need to Add Hyperlinks to Dynamic Validator Validation Summary Error Descriptions in a dynamic Data Application, eApp, that uses field templates (defines different field types), entity templates (defines where teh fields and text goes), filters (defines when the fields appear differently), and page templates to dynamically generate a complete form (different based on state selected) as an Application on the Edit.aspx Custom Page.
Since the application is so long, it's important to make it easy for the user to find which question the validation error occured on.
Example: If the following validation error is thrown:
Requested Effective Date is required for Medicare Supplement Coverage (Applicant A).
Add a hyperlink that jumps to the field or answer given by the user that is causing the error
I may be off, but I was thinking I could use the BaseValidator.SetFocusOnError Property somehow, which gets or sets a value that indicates whether focus is set to the control specified by the ControlToValidate property when validation fails.
If adding hyperlinks to the validation summary isn't possible, I could more easily: - Add Section # & Question # to each Validation Description - Provide links to jump to each of the 7 Sections at the top of the application page
ASP.NET Code on the Edit.aspx Custom Page that tells the browser what dynamic data goes where:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
HeaderText="The following errors occured:" CssClass="DDValidator" />
<company:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="FormView1" Display="None" CssClass="DDValidator" />
<asp:FormView runat="server" ID="FormView1" DataSourceID="DetailsDataSource" OnItemDeleted="FormView1_ItemDeleted" RenderOuterTable="false">
<ItemTemplate>
<table id="detailsTable" class="DDDetailsTable" cellpadding="6">
<asp:DynamicEntity runat="server" />
Under EntityTemplate, the MedSupLife_Section02.ascx page defines where the dynamic controls are but does not list the validation errors:
1. Are you covered under Medicare Part A?
<br/>If "YES", what is your Part A effective date?
<asp:DynamicControl runat="server" DataField="MedPartAEffDate_A" OnInit="DynamicControl_Init" /> /
<asp:DynamicControl runat="server" DataField="MedPartAEffDate_B" OnInit="DynamicControl_Init" />
<br/>If "NO", what is your eligibility date?
<asp:DynamicControl runat="server" DataField="MedPartAEligDate_A" OnInit="DynamicControl_Init" /> /
<asp:DynamicControl runat="server" DataField="MedPartAEligDate_B" OnInit="DynamicControl_Init" />
Under DynamicValidator.cs page the progression of validation is layed out.
On the DateTime_Edit.ascx Field Template Page the Required Field, Regular Express, Dynamic, and Custom Validators are defined:
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" CssClass="DDControl DDValidator" ControlToValidate="TextBox1" Display="Static" Enabled="false" />
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1" CssClass="DDControl DDValidator" ControlToValidate="TextBox1" Display="Static" Enabled="false" />
<asp:DynamicValidator runat="server" ID="DynamicValidator1" CssClass="DDControl DDValidator" ControlToValidate="TextBox1" Display="Static" />
<asp:CustomValidator runat="server" ID="DateValidator" CssClass="DDControl DDValidator" ControlToValidate="TextBox1" Display="Static" EnableClientScript="false" Enabled="false" OnServerValidate="DateValidator_ServerValidate" />
On MedLifeApplication.cs the validators are defined:
public IEnumerable<ValidationResult> ValidateApplicant(ValidationContext validationContext, Applicant a)
{
if (ForMedCoverage)
{
if (!a.RequestedEffectiveDate.HasValue)
{
yield return new ValidationResult("Requested Effective Date is required for Medicare Supplement Coverage (Applicant " + a.Code + ").", new[] { "RequestedEffectiveDate_" + a.Code, "ForMedCoverage" });
}
Sorry about all the code.
Let me know if you need anything else.