locked
ValidationSummary doesn't show up for checkbox w/CausesValidation set true. RRS feed

  • Question

  • User-670301532 posted

    I have the following in the markup (css bits removed for clarity here):

    <asp:ValidationSummary ID="vsInspection" runat="server" DisplayMode="BulletList" HeaderText="Please fix the following errors:" EnableClientScript="true" ShowSummary="true" ValidationGroup="ValidInsp" />
    
    <asp:CheckBox ID="cbxNewPhotos" runat="server" AutoPostBack="true" OnCheckedChanged="cbxNewPhotos_CheckedChanged"        ClientIDMode="Static" CausesValidation="true" ValidationGroup="ValidInsp" />
    
    <asp:ImageButton ID="ibtnSaveInspection" runat="server" OnClick="ibtnSaveInspection_Click" ToolTip="Save."
             ImageUrl="~/images/Icons-Save.png" CausesValidation="true" ValidationGroup="ValidInsp" />

    And in the codebehind:

            protected void cbxNewPhotos_CheckedChanged(object sender, EventArgs e)
            {
                // Validate and save the inspection record before doing 
                // other stuff.
                if (Page.IsValid)
                {
                    SaveInspection();
                    // do other page responsy stuff
                }
            }
    
            protected void ibtnSaveInspection_Click(object sender, ImageClickEventArgs e)
            {
                if (Page.IsValid)
                {
                    SaveInspection();
    
                    // Followup action based on input
    
                }
            }
    

    There are a small number of fields on the screen, all with required field validator attached to them.  If I click the ibtn control the validation happens and the click handler does the correct thing if not valid (do nothing) and the page re-displays with the validation summary control showing the bulleted list of messages and the validators "*" mark next to the field(s) with issues.  If I check (or uncheck at the moment either way) the cbx control the handler does the correct thing if not valid (do nothing) and the page re-displays without the validation summary control but correctly showing the "*" marks next to the fields with issues. 

    I've been wrestling with this all morning and searching and trying things to no avail.  Any ideas/suggestions what I'm missing?

    Thursday, November 5, 2020 9:06 PM

Answers

  • User-670301532 posted

    I have found a solution that works which I share here in case someone else ever runs into a similar situation.  The solution was to wrap the ValidationSummary control in another separate UpdatePanel and specify the checkbox control as a trigger.  Works great now.  Here's the revised markup for the where the ValidationSummary control is in the page:

    <asp:UpdatePanel ID="upVsInspection" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="cbxNewPhotos" />
        </Triggers>
        <ContentTemplate>
            <asp:ValidationSummary ID="vsInspection" runat="server" DisplayMode="BulletList" HeaderText="Please fix the following errors:" EnableClientScript="true" ShowSummary="true" ValidationGroup="ValidInsp" />
        </ContentTemplate>
    </asp:UpdatePanel>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 5, 2020 11:09 PM

All replies

  • User-670301532 posted

    After another 90 minutes I've discovered that the page contains an asp:updatepanel control.  The imagebutton and validationsummary are outside of the updatepanel.  The fields, validators, and (importantly) the checkbox are inside the updatepanel.  This means the validation summary would not be updated when the checkbox autopostback happens.

    Thursday, November 5, 2020 10:46 PM
  • User-670301532 posted

    I have found a solution that works which I share here in case someone else ever runs into a similar situation.  The solution was to wrap the ValidationSummary control in another separate UpdatePanel and specify the checkbox control as a trigger.  Works great now.  Here's the revised markup for the where the ValidationSummary control is in the page:

    <asp:UpdatePanel ID="upVsInspection" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="cbxNewPhotos" />
        </Triggers>
        <ContentTemplate>
            <asp:ValidationSummary ID="vsInspection" runat="server" DisplayMode="BulletList" HeaderText="Please fix the following errors:" EnableClientScript="true" ShowSummary="true" ValidationGroup="ValidInsp" />
        </ContentTemplate>
    </asp:UpdatePanel>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 5, 2020 11:09 PM