Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 778751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:48:57+00:00 2026-05-14T19:48:57+00:00

On the page load i wanna call a custom validator which validates my page

  • 0

On the page load i wanna call a custom validator which validates my page and display corresponding error messages.
How can i do this?

I am using javascript in the custom validator.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:48:57+00:00Added an answer on May 14, 2026 at 7:48 pm

    You can use Page.IsValid and Page.Validate()

    http://weblogs.asp.net/rajbk/archive/2007/03/15/page-isvalid-and-validate.aspx

    After Edit: // Here is a working sample:

    JS:

    <script type="text/javascript">
        function EmpIDClientValidate(ctl, args) {
            // the value is a multiple of 5 if the module by 5 is 0
            args.IsValid = (args.Value % 5 == 0);
        }
    </script>
    

    Aspx:

    <table>
            <tr>
                <td>
                    ID (multiple of 5):
                </td>
                <td>
                    <asp:TextBox runat="server" Width="200px" ID="EmpID" Text="12"/>
                    <asp:RequiredFieldValidator runat="server" ID="ValidateEmpID" ControlToValidate="EmpID"
                        ErrorMessage="ID is required" Display="dynamic">*
                    </asp:RequiredFieldValidator>
                    <asp:CustomValidator runat="server" ID="ValidateEmpID2" ControlToValidate="EmpID"
                        ClientValidationFunction="EmpIDClientValidate" ErrorMessage="ID must be a multiple of 5"
                        Display="dynamic" OnServerValidate="ValidateEmpID2_ServerValidate">*
                    </asp:CustomValidator>
                </td>
            </tr>
        </table>
        <br />
        <asp:Button runat="server" Text="Submit" ID="Submit" OnClick="Submit_Click" /><br />
        <br />
        <asp:CheckBox runat="server" ID="chkEnableValidators" Checked="True" AutoPostBack="True"
            Text="Validators enabled" OnCheckedChanged="OptionsChanged" />
        <br />
        <asp:CheckBox runat="server" ID="chkEnableClientSide" Checked="True" AutoPostBack="True"
            Text="Client-side validation enabled" OnCheckedChanged="OptionsChanged" />
        <br />
        <asp:CheckBox runat="server" ID="chkShowSummary" Checked="True" AutoPostBack="True"
            Text="Show summary" OnCheckedChanged="OptionsChanged" />
        <br />
        <asp:CheckBox runat="server" ID="chkShowMsgBox" Checked="False" AutoPostBack="True"
            Text="Show message box" OnCheckedChanged="OptionsChanged" />
        <br />
        <br />
        <asp:ValidationSummary runat="server" ID="Summary" DisplayMode="BulletList" HeaderText="<b>Please review the following errors:</b>"
            ShowSummary="true" />
        <asp:Label runat="server" ID="Result" ForeColor="magenta" Font-Bold="true" EnableViewState="False" />
    

    And codebehind:

    protected void Page_Load(object sender, EventArgs e)
    {
        // To run all validators
        Page.Validate();
        // To run just one validator:
        ValidateEmpID2.Validate();
    }
    
    protected void Submit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
            Result.Text = "Thanks for sending your data";
        else
            Result.Text = "There are some errors, please correct them and re-send the form.";
    }
    
    protected void ValidateEmpID2_ServerValidate(object source, ServerValidateEventArgs args)
    {
        try
        {
            args.IsValid = (int.Parse(args.Value) % 5 == 0);
        }
        catch
        {
            args.IsValid = false;
        }
    }
    
    protected void OptionsChanged(object sender, EventArgs e)
    {
        // Examine all the validators on the back.
        foreach (BaseValidator validator in Page.Validators)
        {
            // Turn the validators on or off, depending on the value
            // of the "Validators enabled" check box (chkEnableValidators).
            validator.Enabled = chkEnableValidators.Checked;
    
            // Turn client-side validation on or off, depending on the value
            // of the "Client-side validation enabled" check box
            // (chkEnableClientSide).
            validator.EnableClientScript = chkEnableClientSide.Checked;
        }
    
        // Configure the validation summary based on the final two check boxes.
        Summary.ShowMessageBox = chkShowMsgBox.Checked;
        Summary.ShowSummary = chkShowSummary.Checked;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On page load, using jQuery how can I select all check boxes in a
On page load I'm bootstrapping my data to my collections via this technique .
I understand that the page load of asp.net (mvc 2.0ish) sites can suffer for
I'm doing a page with jsf 2.0 and i wanna do something like this:
During page load, index 0 was already selected. Then this code statement selected index
Basically all i wanna do is something like this. var myVar = $.load(phpscript.php,var=one); phpscript.php
On page load i am adding this code if (Request.Cookies[switchstyle] != null) { string
On page load I need to call an API. When all AJAX call are
On page load, I'm loading an html page through jquery ajax. This html page
I wish a page to fully load before issuing an ajax call to update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.