RequiredValidator fires but runs at server anyway

Hi. As title states, when I click on my button Validator fires but it doesn't stay in the client, it runs at server. When return, you can see the validator text.

<RadzenTemplateForm  TItem="SearchInfo" Data=@searchInfo>
    <ChildContent>
        <p style="margin-bottom:25px;">
            <table>
                <tr>
                    <td>
                        <RadzenLabel Text=@localizer["reporttypelabel"] />
                        <RadzenDropDown Data="@reportTypes" Name="ddlTypes" TextProperty="_sReportTypeName" ValueProperty="_iReportTypeOrder" @bind-Value=@searchInfo.iSelectedType Style="width:220px" />  
                        <RadzenRequiredValidator DefaultValue="0" Component="ddlTypes" Text="*Field required." Popup=false Style="position: absolute; margin-bottom:20px;" />
                    </td>
                </tr>
            </table>
        </p>
        <table>
            <tr>
                <td>
                    <p style="margin-bottom:25px;">
                        <RadzenLabel Text=@localizer["datefromlabel"] />
                        <RadzenDatePicker @bind-Value=@searchInfo.dSelectedDateFrom Name="dpFrom" Style="width:120px" DateFormat="d" AllowClear="false" />
                        <RadzenRequiredValidator Component="dpFrom" Text="*Field required." Popup=false Style="position: absolute; margin-bottom:20px;" />
                    </p>
                </td>
                <td>
                    <p style="margin-bottom:25px;">
                        <RadzenLabel Text=@localizer["datetolabel"] />
                        <RadzenDatePicker @bind-Value=@searchInfo.dSelectedDateTo Name="dpTo" Style="width:120px" DateFormat="d" AllowClear="false" />
                        <RadzenRequiredValidator Component="dpTo" Text="*Field required." Popup=false Style="position: absolute; margin-bottom:20px;" />
                    </p>
                </td>
            </tr>
        </table>
        <p style="padding: 25px 0px 0px 15px; ">
            <RadzenButton Text=@localizer["btnsearch"] Click=@(args => DoSearch()) ButtonType="Radzen.ButtonType.Submit" ButtonStyle="ButtonStyle.Light" />
        </p>
        <p><RadzenLabel Text=@searchInfo.message Style="margin: 25px 5px 5px 0px;" /></p>
    </ChildContent>
</RadzenTemplateForm>

Thanks.

1 Like

What does that mean? Validation code always run on the server (as every other Blazor server-side code).

hi korchev,

I mean, I want my button only runs at server when all my required fields are completed. I it runs always then I should check in server if my required fields are completed or not. thanks for answering.

Hi @Mario ,

Are you using the Click event of the button? It would indeed run always regardless of the validation status. You need to use the Submit event of the RadzenTemplateForm instead - it will run only when validation passes.

1 Like

Thank you very much korchev. Now it works as expected.