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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:13:31+00:00 2026-06-14T06:13:31+00:00

Iam trying to validate inputbox for search engine in my MasterPage for which I

  • 0

Iam trying to validate inputbox for search engine in my MasterPage for which I have used custome validator, but it does not validate instead takes me to search result. By default input box has value “Name…”, so on search click it searches with “Name…”.

Also I have submit button on contact us page, when I hit the button the abve validation occurs, which is not related to above search functionality. ere is my code for ref.:-

<script>
function nameNull(oSrc, args) {
            if (name.Value.Trim() == "Name..." || name.Value.Trim() == "") {
                args.IsValid = false;
            }
            else {
                args.IsValid = true;
            }
        }
</script>

<input type="text" id="name" runat="server" value="Name..." name="name" onblur="doDefault(this)" onfocus="doClear(this)" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please enter  name"
ControlToValidate="name" ClientValidationFunction="nameNull"
ForeColor="#FF3300" Font-Bold="True"></asp:CustomValidator>
  • 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-06-14T06:13:32+00:00Added an answer on June 14, 2026 at 6:13 am

    At first you try to access your HTML element by id. To get element you need to use document.getElementById JS method.

    Then you marked input field with runat=”server” attribute. This will cause that ASP.NET will render ClientID which differ from ID you specified in ASP.NET markup. So to access your element you need to use ClientID value of the server control:

    <script type="text/javascript">
        function nameNull(oSrc, args) {
            var element = document.getElementById('<%= this.name.ClientID %>');
            var value = element.value.trim();
    
            if (value == "Name...") {
                args.IsValid = false;
            }
            else {
                args.IsValid = true;
            }
        }
    </script>
    

    The second point as you see is that JavaScript is case sensitive and you need to use value.trim();.

    And the last: to check that element at least has value it is better to use required field validator. So your markup should be modified to be:

    <input type="text" id="name" runat="server" value="Name..." name="name" />
    <asp:RequiredFieldValidator ID="NameFieldRequiredFieldValidator" ErrorMessage="Please enter  name" ControlToValidate="name" />
    <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please enter  name" ControlToValidate="name" ClientValidationFunction="nameNull"
        ForeColor="#FF3300" Font-Bold="True"></asp:CustomValidator>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to validate weather the connection was successful but have been getting
I am trying to validate some information, so I added a validator and used
I am trying to validate my site through the w3c validator, but am getting
I am trying to validate email using javascript but for some reason it is
I am trying to validate an update for an app that I have in
I am trying to validate an XML against schema using LibXML::Schema Validator CPAN module.
I am trying to validate some form fields but it always errors out on
I am trying to validate a phone number which is contained over two fields.
I am trying to validate home address that is street address. But it returns
I am trying to validate a phone number. The website is US based but

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.