Search code examples
c#validationwebformslinkbutton

Can I validate just a Page/Validation Group with OnClientClick?


This is my code:

<asp:LinkButton 
OnClientClick="Page_ClientValidate(); if(Page_IsValid==false) { console.log('validate'); return false; }" 
ID="LinkButton1" 
ValidationGroup="validPanel1" 
runat="server">Check</asp:LinkButton>

but when I click on it, it try to validate the whole Page. I just need to validate the validPanel1's Page. Is it possible?


Solution

  • you can do this by simply provide the validation group name to Page_ClientValidate

    <asp:LinkButton OnClientClick="Page_ClientValidate('Your_ValidationGroup_Name'); if(Page_IsValid==false) { console.log('validate'); return false; }" 
    ID="LinkButton1" ValidationGroup="validPanel1" runat="server">Check</asp:LinkButton>
    

    kindly check this question. It's about another problem but he first do what you want to do.