Asp.net postback prevented after checking clients

I have an asp.net form that contains a drop-down list that is sent back to the server upon change and populates the second drop-down list with several dates.

The form also contains other fields, some of which are verified clients and some servers.

Here is the problem I am having. If I get a client validation error, try changing the drop-down list, the second drop-down list will not be filled. If I change the first drop-down list again, it will work as expected.

Here is my submit button:

<asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClientClick="Page_ClientValidate(); return checkPassengers();" OnClick="Page_Transfer" ValidationGroup="FormSubmit" />

Here is my customer check:

function checkPassengers() {
    if($("#testField").val() == "Name *" || $("#testField").val() == "") {
            $("#pltester").prepend("<p class='fillall'>Please fill in all fields marked with *</p>");
            return false;       
    }
};

Dropdowns:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddl1st" EventName="SelectedIndexChanged" />
    </Triggers>
    <ContentTemplate>
        <asp:DropDownList ID="ddl1st" Width="190" AutoPostBack="true" OnSelectedIndexChanged="ChooseDates1st" runat="server" />
        <asp:DropDownList ID="ddlDepart1st" AutoPostBack="true" runat="server" />
    </ContentTemplate>
</asp:UpdatePanel>
+3
source share
4 answers

, .

, , CausesValidation="true" , - .

, !

+4

CausesValidation="true" . asp dropdownlist SelectedIndexChange. , , reset js .

function ignoreValidation() {
            if (typeof Page_ClientValidate != 'undefined') {
                Page_ClientValidate('reset-validation');
                Page_BlockSubmit = false;
            }
            return true;
}

<asp:DropDownList CausesValidation="false" onchange="ignoreValidation();" runat="server" ID="CustomerDropDownList" OnSelectedIndexChanged="LoadCustomers" AutoPostBack="true"/>

+3

, CausesValidation="false" . , , .

Alternatively, you can put the DropDownList in another ValidationGroup so that changing it does not cause validation on other controls.

+1
source
function validateCommand(group) {
        if (typeof (Page_ClientValidate) == 'function') {
            Page_ClientValidate(group);
            if (Page_IsValid) {
                Page_BlockSubmit = !confirm('Are you sure?');
            }
        }
    }
0
source

All Articles