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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:57:14+00:00 2026-06-17T02:57:14+00:00

After incorporating what I’ve learned by reading the answers to this question , I’ve

  • 0

After incorporating what I’ve learned by reading the answers to this question, I’ve figured out how to generate an error message when, in an autocomplete field the user enters text that doesn’t correspond to any of the available selections.

This page is an ASP.NET page which already has an infrastructure of ASP.NET validators on it. What I want to happen is to introduce a validator onto the page that causes page validation to fail when the user enters something not in the list. Here’s what I have so far:

I started with Anonymous’s answer to the question above:

change: function (event, ui) {
        if (!ui.item) {
             $(this).val('');
         }
    }

I replaced it with this in my autocomplete() javascript:

    change: function (event, ui) {
        if (!ui.item) {
             $(""#" + lblAutocompleteError.ClientID + @""").show();
             $(""#" + txtDummy.ClientID + @""").val('');
        } else {
             $(""#" + lblAutocompleteError.ClientID + @""").hide();
             $(""#" + txtDummy.ClientID + @""").val('Dummy');
        }
    },

It’s javascript that’s being generated in code-behind rather than on the front end, that’s why it has all that literal string goodness…

And on the front end, I’ve declared two controls: txtDummy which I set and clear based on whether the autocomplete contains a matching string, and rfvDummy that requires said TextBox to be populated.

<asp:RequiredFieldValidator runat="server" ID="rfvDummy" 
    ControlToValidate="txtDummy" />
<asp:TextBox runat="server" ID="txtDummy" Text="Dummy" Visible="false" />

Problem is, the RequiredFieldValidator isn’t failing when it should. More importantly, I get this sinking feeling that I’m going down the wrong path here. Creating a hidden TextBox and a RequiredFieldValidator seems like way too much of a hack for what I’m trying to accomplish. Is there a straightforward way to cause a page to fail validation, on the client side, with a message formatted like my other validators, when the user enters a value that is not in the autocomplete list?

  • 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-17T02:57:15+00:00Added an answer on June 17, 2026 at 2:57 am

    My autocomplete logic was correct, it was the means of hiding the txtDummy control that was not. By using

    Visible="false"
    

    the HTML for txtDummy is not generated, so the RequiredFieldValidator has nothing to look at. Changing the code for the TextBox to:

    <asp:TextBox runat="server" ID="txtDummy" Text="Dummy" style="display: none;" />
    

    allowed the HTML to be generated. When my change clause, above, is invoked, the page now fails validation when a matching item is not selected in the TextBox.

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

Sidebar

Related Questions

After deploying WCF server (svc) on my Server, I have got this message when
I've searched around for answers to this question, but not found anything quite on
After answering this question I put together the following C# code just for fun:
After reading a question on the difference between pointers and references , I decided
After incorporating Ben Voigt's answer into the code, it appears to work Original question:
After reading this article I made a point that int () yields 0 because
After I posting this question I tried to reproduce the problem of accidental rvalue
After browsing the web I have found out that this code is supposed to
After extensive searching on this matter, I have been unable to find an answer
After writing out some processed content to an output stream, I need to revisit

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.