Search code examples
asp.netvalidationmaster-pagescustomvalidator

Custom validator with master page button click


i have a custom validator in a content page

<asp:CustomValidator id="CustomValidator1" runat="server" 
   OnServerValidate="RevisionValidate" 
   ControlToValidate="TextBoxRevisionOrder" 
   ErrorMessage="Invalid RevOrder Format">
</asp:CustomValidator> 

where RevisionValidate is a serverside method

protected void RevisionValidate(object source, ServerValidateEventArgs args)
    {
               //Code goes here           
             if (CurrentRevisionOrder != "-1" && ChangedRevisionOrder == "-1")
                            {
                                val = "Not Valid";


                            }
                            else
                            {
                                val = "Valid";

                            }
                            args.IsValid = (val == "Valid");
                        }

Custom validator fires perfectly on content page button click but the issue is i also have a button in the master page which the custom validator need to fire.with my current code it's not firing on master page button click.any help?


Solution

  • Found the solution. I had to check

    if(Page.IsValid)
    {
    
    }