How do you do validation with 2 buttons in a single ASP.NET page with masterpage?

StackOverflow https://stackoverflow.com/questions/22676555

  •  22-06-2023
  •  | 
  •  

Вопрос

So I have 2 buttons, 2 RequiredFieldValidator and 2 validation summary that triggers to the RequiredFieldValidator. How do I make 1 button to perform a validation for the let's say validator1 and another button to perform another validation by the validator2 and displays its result with their own separated validation summary?

In my masterpage, I wrap my contentplaceholder1 with a runat server form. In that contentplateholder1, is my 2 separated form that requires the 2 individual form inputs

Это было полезно?

Решение

You can group these controls for validation purposes by setting the ValidationGroup property. If you set button1's ValidationGroup property to "group1"...

 <asp:Button ValidationGroup="group1" ...></asp:Button>

Then, all validation controls that belong to the same group will perform user input validation when this button is clicked. Here's an example of how set the validation group for validation controls...

<asp:ValidationSummary ValidationGroup="group1" ...></asp:ValidationGroup>
<asp:RequiredFieldValidator ValidationGroup="group1" ...></asp:RequiredFieldValidator>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top