将超链接添加到动态数据验证摘要,以通过 SetFocusOnError 跳转到有错误的字段

发布于 2024-11-28 22:17:54 字数 3703 浏览 0 评论 0原文

问题:我需要在动态数据应用程序 eApp 中添加超链接到动态验证器验证摘要错误描述,该应用程序使用字段模板(定义不同的字段类型)、实体模板(定义字段和文本的位置)、过滤器(定义何时字段显示不同),以及页面模板,用于动态生成完整的表单(根据所选状态而不同)作为 Edit.aspx 自定义页面上的应用程序。

由于应用程序很长,因此让用户轻松找到验证错误发生在哪个问题上非常重要。

示例:如果抛出以下验证错误:

   Requested Effective Date is required for Medicare Supplement Coverage (Applicant A).

添加一个跳转到导致错误的用户给出的字段或答案的超链接,

我可能会关闭,但我想我可以使用 BaseValidator.SetFocusOnError 属性,它获取或设置一个值,该值指示验证失败时是否将焦点设置到 ControlToValidate 属性指定的控件。

如果无法将超链接添加到验证摘要,我可以更轻松地: - 添加第 # 节和第 # 节每个验证描述的问题# - 提供跳转到应用程序页面顶部 7 个部分中每个部分的链接

Edit.aspx 自定义页面上的 ASP.NET 代码告诉浏览器动态数据的去向:

<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" />

在 EntityTemplate 下,MedSupLife_Section02.ascx 页面定义了动态数据的位置动态控件是但不列出验证错误:

    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" />

在 DynamicValidator.cs 页面下,列出了验证的进度。

在 DateTime_Edit.ascx 字段模板页面上定义了必填字段、正则 Express、动态和自定义验证器:

  <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" />

在 MedLifeApplication.cs 上定义了验证器:

    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" });
            } 

对所有代码感到抱歉。

如果您还需要什么,请告诉我。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文