简体   繁体   中英

Fire postback after javascript validation

I have the following aspx code:

<td>
    <p>Customer*</p>
</td>
<td>
    <asp:TextBox ID="TextBoxCustomer" list="SiteMainContent_Customers" runat="server" OnTextChanged="CustomerTextChanged" AutoPostBack="true" required CssClass="form-control" />
    <datalist id="Customers" runat="server"></datalist>
</td>
<td class="auto-style1">
    <asp:RequiredFieldValidator ID="RequiredFieldValidatorKunde" runat="server" ControlToValidate="TextBoxCustomer"
        CssClass="Error" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator>
    <asp:CustomValidator ID="CustomCustomerValidator" runat="server" ControlToValidate="TextBoxCustomer" ErrorMessage="Customer not in CRM"
        OnServerValidate="ValidateCustomer" CssClass="Error"></asp:CustomValidator>
</td>

The custom validator:

public void Validate(object source, ServerValidateEventArgs args)
{
    try
    {
        GetCompanyId(args.Value);
    }
    catch (Exception ex)
    {
        ((CustomValidator)source).ErrorMessage = ex.Message;
        args.IsValid = false;
        return;
    }
    args.IsValid = true;
}

The code is a snippet of my whole aspx page. If some of the other field's doesnt validate and you have to correct the data, the TextBoxCustomer does not postback to the codebehind anymore.

What can I do to get TextBoxCustomer to postback, even if I have clicked Submit and the data in the fields did not validate?

It is somewhat related to No postback after Javascript function - I think it is because the validations return false.

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