动态创建的自定义验证程序不会向验证摘要添加错误消息

时间:2012-07-02 19:56:14

标签: asp.net customvalidator

您能否告诉我,为什么自定义验证器(动态创建),此处的信息未添加到验证摘要中?是因为updatepanel?如何使它工作? 我绝对筋疲力尽,但找不到合适的解决方案......

MultiFreeSet控制代码隐藏:

protected void btnPatternAdder_Click(object sender, EventArgs eventArgs)
{
    var includeEventArgs = new IncludeEventArgs();
    baseTSMAlertConfigEditControlWithInclude.btnPatternAdder_Click(sender, includeEventArgs);
    if (includeEventArgs.Cancel)
    {
        /*
        var ClientValidationFunctionName = string.Format("{0}_ClientValidation", ID);
        Page.ClientScript.RegisterClientScriptBlock(
                                                GetType(),
                                                string.Format("{0}_validationScript", ID),
                                                string.Format("function {0}(sender, eventArgs) {{ eventArgs.errormessage = '{1}', eventArgs.IsValid = false; return; }}",
                                                ClientValidationFunctionName,
                                                includeEventArgs.Message));
        */
        var customValidator = new CustomValidator
        {
            //ClientValidationFunction = ClientValidationFunctionName,
            ValidationGroup = ValidationGroup,
            IsValid = false,
            ErrorMessage = includeEventArgs.Message,
            Display = ValidationDisplayType
        };
        Page.Validators.Add(customValidator);
    }
}

MultiFreeSet控制标记:

<asp:UpdatePanel ID="upFreeSet" runat="server">
<ContentTemplate>
...
    <asp:PlaceHolder runat="server" ID="phIncludePattern" Visible="false">
    <tr>
        <td class="SubHead">[IncludeCaption]</td>
        <td>
            <asp:TextBox ID="txtIncludePattern" runat="server" Text="" CssClass="MediumTextBox" />
            </td>
            <td>
                <asp:Button CommandName="ListAdder" ID="btnPatternAdder" runat="server" CssClass="buttonClass displayBlock" Text="Add" OnClick="btnPatternAdder_Click" />
            </td>
        </tr>
        <tr>
        <td class="SubHead ta">[IncludedCaption]</td>
        <td>
            <asp:ListBox ID="lboxIncludePattern" runat="server" SelectionMode="Multiple" Rows="7" CssClass="LargeDropDownList" />
    <asp:ObjectDataSource ID="odsIncludePattern" runat="server" />
</td>
<td class="ta">
<asp:Button CommandName="ListDeleter" ID="btnPatternDeleter" runat="server" CssClass="buttonClass displayBlock" Text="Delete selected" OnClick="btnPatternDeleter_Click" />
    </td>
    </tr>
    </asp:PlaceHolder>
...
</ContentTemplate>

主控制标记:

<asp:FormView>
    <EditItemTemplate>
        ...
        <ac:multiFreeSet ID="multiNodePatternInclusions" ValidationGroup="vgFrmConfigEdit" IgnoreCase="True" runat="server" Caption="Include node name patterns" IncludeCaption="Add node name pattern" IncludedCaption="Included node name patterns" />
        <XXX:SaveButton ID="btnImgSave" runat="server" ValidationGroup="vgFrmConfigEdit" />
        <XXX:CancelBackButton ID="btnImgCancel" runat="server" />
        <asp:ValidationSummary ID="valSummary" runat="server" ValidationGroup="vgFrmConfigEdit" CssClass="NormalRed" ShowSummary="True" />
        ...
    </EditItemTemplate>
</asp:FormView>

1 个答案:

答案 0 :(得分:0)

行。嗯..我不得不在更新面板内部使用单独的验证组创建单独的验证摘要..