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 7620701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:00:02+00:00 2026-05-31T04:00:02+00:00

How can I implement a clientsidevalidation required textfields which contain the following texts: [Name

  • 0

How can I implement a clientsidevalidation required textfields which contain the following texts:

[Name required]
[Address required]

Preferrably I would like to use the asp:CustomValidator if possible? Only if both fields have data the postback will be triggered?

     <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">        var $j = jQuery.noConflict();</script>
    <script type="text/javascript">


        function otherMessageValidator_ClientValidation(source, args) {
            args.IsValid = false;

            var nm = $j("#name");

            if (nm.val() != "" && nm.val() != "[Name required]") {
                args.IsValid = true;
            }

            return args.IsValid;
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="name" runat="server" ValidationGroup="valgroup">[Name required]</asp:TextBox>
        <asp:TextBox ID="address" runat="server" ValidationGroup="valgroup">[Address required]</asp:TextBox>
    </div>
    <asp:Button runat="server" ID="but1" Text="go" OnClick="but1_Click" />
    <asp:CustomValidator ID="MyCustomValidator" runat="server" ValidationGroup="valgroup"
        ClientValidationFunction="otherMessageValidator_ClientValidation" ErrorMessage="At least one textbox needs to be filled in." />
    </form>
</body>
</html>
  • 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-31T04:00:04+00:00Added an answer on May 31, 2026 at 4:00 am

    One way to achieve it is by using regular expression from javascript and validation it client side only. So in the mentioned code it will only go to server if all the required validations are fulfilled else it will show the Error message on the screen in the Summary div tag.

    Following is the required code.

     <script type="text/javascript">               
     function validateFields() {
    
                    var message = "";
                    var error = false;
    
                   var name = document.getElementById("<%=txtname.ClientID %>");
                    var address = document.getElementById("<%=txtaddress.ClientID %>");
    
                    //work as required field validation
                    if ((/\S+/.test(name.value)) == false) {
    
                        message += "Enter Name" + "<br>";
                        error = true;
                    }
                    //work as required field validation
                    if ((/\S+/.test(address.value)) == false) {
    
                        message += "Enter Address" + "<br>";
                        error = true;
                    }
    
    
                    if (error) {
                            document.getElementById("validationSummary").innerHTML = message;
                            document.getElementById("validationSummary").style.display = "block";
                            return false;
                        } else {
                            document.getElementById("validationSummary").innerHTML = "";
                            document.getElementById("validationSummary").style.display = "none";
                            return true;
                        }
    
    
                    }
     </script>
    

    and we need to take one div for displaying validationsummary and the button

    <div id="validationSummary" style="display: none; float: left">
                                    </div>
      <asp:LinkButton ID="lnkAddNew" runat="server" OnClientClick="return validateFields()" OnClick="lnkAddNewPatient_Click" >Save</asp:LinkButton>
    

    Hope it will solve your issue

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In java a class can implement Iterable which lets you use the foreach() statement
I am wondering how I can implement something like the following: test(){ cat>file<<'EOF' abc
Can someone please tell me how I can implement the following line of pseudo-code.
How I can implement dynamic Jtree, which shows created instances of clases? For example,
Is there any way I can implement functionality which will clear all my data/files/shared_preferences/database
It seems like both can be used to define functions that you can implement
Is there any standard library of Matrix in c. Which I can implement across
How can implement an intent for sharing some text in a dialog like this
How can I use the Bouncy Castle provider to implement algorithms such as Serpent
I'm a little stuck here on how I can implement the following fade in/out

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.