简体   繁体   中英

requiredfieldvalidator stops valid event

I have a requiredfieldvalidator for a dropdownlist. Code:

<asp:DropDownList ID="ddlSoortGebeurtenissen" runat="server" 
                    DataSource="<%# SoortGebeurtenissen %>" CssClass="inputtext" 
                    CausesValidation="False" ValidationGroup="valGroupSelectControls" 
                    DataTextField="Title" DataValueField="ID" AutoPostBack="True" 
                    OnSelectedIndexChanged="ddlSoortGebeurtenissen_SelectedIndexChanged">
                </asp:DropDownList>
                <asp:RequiredFieldValidator ID="requiredValidatorSoortGebeurtenis" runat="server"
                    ErrorMessage="Invullen van Soortgebeurtenis is verplicht" 
                    ToolTip="Invullen van Soortgebeurtenis is verplicht"
                    ControlToValidate="ddlSoortGebeurtenissen" 
                    Display="Dynamic" 
                    CssClass="ui-icon-errormsg"
                    Text="Invullen van Soortgebeurtenis is verplicht"
                    ValidationGroup="valGroupSelectControls" />  

The selectedIndexChanged event fires when needed, except when the validation has been done before. When I press the submit button having selected an empty value, the validator nicely shows me the error message. Then when I change the selection, and expect the selectedIndexChanged event to fire, it doesn't fire. Nothing happens until I trigger another postback. (lets say the close button). Then the selectedIndexChanged event is fired AND the event of the actual button is fired.

Somehow the selectedIndexChanged event sticks around until the next postback, but does not cause the postback itself. This only happens when the validation shows the error beforehand.

从下拉列表中删除CausesValidation="False"属性

Try using

EnableClientScript="False"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM