Custom Validator utility but does not update ValidationSummary

Hey. I am working on a special form field validation tool, it seems that the custom validator works by not allowing it to go to the next page, but it does not update the validation summary and does not display an asterisk and shortcuts that I made visible. I also have other validators, such as RequiredFieldValidator in the same field. My ValidationGroup is installed, as are Text and IsValid. I even wrote and installed client-side authentication method in javascript, as some workarounds suggest.

here is the summary verification code in asp.net

<asp:ValidationSummary ID="ValidatorSummary" runat="server" ValidationGroup="Step2" />

here is a custom validator and a required field 1

<asp:CustomValidator ID="AddressVerification" runat="server" ErrorMessage="Please enter a valid address." Display="Dynamic" ValidationGroup="Step2" OnServerValidate="AddressVerification_ServerValidate" ClientValidationFunction="CustomValidatorDummy" Text="*" Enabled="true" EnableClientScript="true"></asp:CustomValidator>
<asp:RequiredFieldValidator ID="RFValidatorHomeAddress" runat="server" ErrorMessage="Please enter home address." Text="*" Display="Dynamic" ValidationGroup="Step2" ControlToValidate="txtHomeAddress"></asp:RequiredFieldValidator>

here a special verification method is used in the code <

protected void AddressVerification_ServerValidate(object sender, ServerValidateEventArgs e)
{
//lets just say it doesn't validate and sets the IsValid to false
lblUspsValidatorResHomeCity.Visible = true;
lblUspsValidatorResHomeState.Visible = true;
lblUspsValidatorResHomeZip.Visible = true;
e.IsValid = false;
}

please advise, thanks.

EDIT: - . . !

:

<asp:UpdatePanel ID="UpdatePanelValidationSummaryHome" ChildrenAsTriggers="false" UpdateMode="Conditional"
runat="server">
<ContentTemplate>
    <asp:ValidationSummary ID="AddressHomeValidationSummary" runat="server" ValidationGroup="AddressHomeValidationGroup"
        CssClass="errors" /> 
</ContentTemplate>

:

UpdatePanelValidationSummaryHome.Update();
+3
3

, ControlToValidate CustomValidator.

CustomValidator , :

ASPX

<asp:TextBox ID="txtMyTextBox" runat="server" />
<asp:CustomValidator ID="AddressVerification" runat="server"
    Display="Dynamic"
    ErrorMessage="Please enter a valid address."
    OnServerValidate="AddressVerification_ServerValidate"
    Text="*"
    ValidationGroup="Step2" />
<asp:RequiredFieldValidator ID="rfvAddress" runat="server"
    ControlToValidate="txtMyTextBox"
    Display="Dynamic"
    ErrorMessage="Please enter an address"
    Text="*"
    ValidationGroup="Step2" />
...
<asp:ValidationSummary ID="ValidatorSummary" runat="server"
    ValidationGroup="Step2" />
...
<asp:Button ID="btnCheckAddresses" runat="server"
    CausesValidation="true"
    Text="Check Addresses"
    ValidationGroup="Step2" />

CS

protected void AddressVerification_ServerValidate(object source, ServerValidateEventArgs args) {
    args.IsValid = !string.IsNullOrEmpty(txtMyTextBox.Text) && !txtMyTextBox.Text.Contains(' ');
}

, , -, CausesValidation="true" ValidationGroup, .

2

UpdatePanel, ValidationSummary , ValidationSummary. postback UpdatePanel, , , ValidationSummary.

, UpdatePanel, , UpdatePanel.

MSDN,

ValidationSummary UpdatePanel, , , . UpdatePanel , . " " .

MSDN.

+6

, ( , ..), , RequiredValidator, CustomValidator ValidationSummary ValidationGroup.

.

<asp:CustomValidator ID="CustomValidator6" runat="server" ErrorMessage="The field is required"
ValidationGroup="myValGroup">*</asp:CustomValidator>

, , .

0

, "" .

<Triggers>                        
<asp:PostBackTrigger ControlID="ButtonSubmit" />
</Triggers>

, .

0

Source: https://habr.com/ru/post/1777546/


All Articles