Search code examples
asp.netcustomvalidator

Dynamically created custom validator does not add error message to validation summary


could you please tell me, why custom validator (created dynamically), information here is not added to validation summary? Is it because of updatepanel? How to make it work? I am absolutely exhausted, but cannot find appropriate solution...

MultiFreeSet control code-behind:

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 control markup:

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

Main control markup:

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

Solution

  • OK. Well.. I had to create a separate validation summary with separate validation group inside update panel..