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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:40:20+00:00 2026-05-27T14:40:20+00:00

My ASP.NET MVC 3 website has code on the server side that checks for

  • 0

My ASP.NET MVC 3 website has code on the server side that checks for the name of the submit button clicked to submit the form. The code works when I use the mouse to click the button, but when I use the Enter key, the form gets posted, but the request doesn’t contain the name of the submit button.

Is there some attribute I can set on the submit button to get this to work for both clicking and using the Enter key?

Here is my HTML:

<div>Search:</div>
  <form action="/Item/Search" method="post">
    <input class="fulltextsearch" id="FTSearchText" name="FTSearchText" type="text" value="" />
     <input type="submit" value="Go" name="FTSearchButton" />
  </form>
</div>

On the server side, I have a custom model binder that uses the following code to determine if the user clicked the submit button.

        // See if the value provider has the required prefix
        var hasPrefix = bindingContext.ValueProvider.ContainsPrefix(bindingContext.ModelName);
        var searchPrefix = (hasPrefix) ? bindingContext.ModelName + "." : string.Empty;

        var searchButton = GetValue(bindingContext, searchPrefix, "FTSearchButton");
        // If this value doesn't have value, the user didn't click the button so exit
        if (string.IsNullOrEmpty(searchButton)) {
            return null;
        }

    private static string GetValue(ModelBindingContext context, string prefix, string key) {
        var result = context.ValueProvider.GetValue(prefix + key);
        return result == null ? null : result.AttemptedValue;
    }

Here is the problem I’m having with this. I have a page that displays a list of items. I have a ‘search’ textbox and a submit button in an HTML form. When the user enters text in the textbox and clicks the search button or uses the enter key, the page posts the form data via HTML GET, and returns the first eight records found. The page then displays page links for additional pages. The problems is that when the user clicks a page link, the form data is all blank, and my filter information is lost (the form isn’t posted with the form value when using these links). So, I end up displaying a blank list of items (blank searches returns zero results) instead of paging the data.

By adding the check for the button name in my form data, I could determine whether or not to simply page the data, or do a new look up.

  • 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-27T14:40:20+00:00Added an answer on May 27, 2026 at 2:40 pm

    So, I researched this last night and almost got somewhere. Then this morning, I really did get somewhere and here’s where I ended up.

    Apparently the W3C standards for form submission are pretty lax when describing the functionality as it relates to the Enter button and submitting forms. It seems they determined that

    When there is only one single-line text input field in a form, the user agent should accept Enter in that field as a request to submit the form.

    So that leaves a lot of wiggle room for the browser makers. Today, virtually all browsers support using the Enter key to submit a form, whether the form contains one or more single line text input boxes.

    The problem I’m having is more or less unique to Internet Explorer, and only when the form contains one, single-line text input control. For whatever reason, Microsoft decided that when Internet Explorer submits a form like this, it doesn’t include the submit button’s name/value pair in the post body. However, it does include the button’s name/value pair if the user clicks the submit button —or— uses the Enter key, and the form contains more than one single-line text input control.

    So, the only solution I can think of or find suggested is to add a second single-line text input to my form, and then set the the style to

    visibility: hidden; display: none;
    

    My form now has two single-line text input controls, so the form will post with the name/value pair in the form body, regardless of whether or not the user used the Enter key or clicked the submit button.

    So, we have a workaround that was discovered by ASP.NET developers. It seems the key/value pair is required by ASP.NET web-forms to fire the click event, so this work around isn’t something new, albeit not my favorite way to do things.

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

Sidebar

Related Questions

running asp.net mvc website that has code that connects to oracle. Works fine on
In my asp.net-mvc website I have a field that usually has a string (from
I've got a simple ASP.NET MVC website. It has Debug, Testing and Release configuration
I am creating an ASP.Net MVC website that I am launching soon in private
I have an ASP.NET MVC website that works in tandem with a Windows Service
i have an asp.net mvc website with a SQL server backend. For every table
I have an asp.net mvc website which of course has a web.config file. I
I have an ASP.NET MVC 3 website that communicates with my iOS app via
We've got an asp.net mvc website that is currently in a private beta state.
I have an ASP.NET (MVC) website that is serving static content (images) as well

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.