.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

I don't want Form to Post with ENTER key

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :ASP.Net
 Hi all, I have done much searching and tried capturing javascript keydown events and such but cannot seem to stop a form from posting upon the user typing the ENTER key. I am using VB with VS 2008 SP1 and .NET 3.5 SP1. However, the ENTER key should function properly within a textarea input. So I have refrained from placing the keydown event in the Body tag. So I have wired up keydown events in 6 <asp:textboxes> that use the AutoComplete Extender. The javascript called is: function on_keydown(e) { var keynum; var keychar; var numcheck; if (window.event.keyCode == 13) { event.returnValue = false; event.cancel = true; } else if (e.which) // Netscape/Firefox/Opera { if (e.which == 13) { e.returnValue = false; e.cancel = true; } } This does not work and the form posts anyway. Actually, for those 6 texboxes I would like the Enter key to act as if Tab has been typed...ideally. Please note that I am also using a Master Page. Also for some reason when I first wrote this app a year ago I chose to use an input for the "save" button as in: <input runat="server" type="Submit" id="btnSave> Lastly I also call a JS validation routine prior to post. Can I retrieve the last keypress within that routine? In Clipper language there was a handy Lastkey function. Yes I've been programming since the DOS days. Can someone tell m

View Complete Post

More Related Resource Links

How to post a form data using Enter key in ASP.NET?

In this article I will explain how to submit a form when user clicks on enter key in asp.net application.

Help with form input and post


I'm trying to teach myself MVC and have been having a few problems trying to handle a form input and post scenario. I am trying to have a section at the top for searching that appears on every page (like there is on sites like amazon).

I've read websites such as: http://weblogs.asp.net/scottgu/archive/2007/12/09/asp-net-mvc-framework-part-4-handling-form-edit-and-post-scenarios.aspx and tried to follow their example form post code in my Site.master file. 

The problem I'm having is that it always calls the default controller action, regardless of what I put as the url in the form action (in fact, I can even remove the form tags altogether and it doesn't seem to make a difference -the text box will still call the default controller when I press enter).

In my site master file, I have tried the using the following html markup:

<form action="Home/SearchResults" method="post">
                    <input id="Search" type="text" name="searchText" />
                    <input type="submit" value="Search" />


which is the for

POST from html form viewstate problem

<p> Hi all, I have a website where people need to pay for a specific download (.pdf file). After they payed they get the download(A). My payment-provider can do a HTML-Postback to the site i want, for each succesfull payment. So the idea is that if someone payed, they do a postback to my server with a couple of parameters, so i can know that that specific email address has payed, and they get the download. I tested localy with a .html file on my desktop to postback a set of parameters to my local asp.net website. But in ONLY works if i include the __VIEWSTATE in my html file. And i cant get rid of the viewstate in my HTML of the aspx page. >test.html: <html><head></head><body> <h1>Dit is een test</h1> <form id="form1" action="http://localhost:25659/WebForm1.aspx" method="POST"> <input id="Button1" type="submit" value="submit!"/> 'IT ONLY WORKS IF I INCLUDE THE NEXT LINE: <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjA0OTM4MTAwNGRk" /> </form></body></html> Has anybody an idea to acomplish my goal? Maybe i can get some info about the postback in my global.asax? or create a HttpHandler for .html files? Anyone?   Thanks in advance, Vincent   </p>

Post the SAML Response in an HTML form to the assertion consumer service

Hi,   Can anyoner please help me in how to post the SAML Response in an HTML form to the assertion consumer service. I have generated the saml reponse and want to send the same to the re-directing url.  

AJAX Form POST Request to a DLL Problem

I am using AJAX javascript for POSTING a complete HTML form to the server which is an external dll on a different server and displaying the response. The server-response is displayed in a "div" . basically i need to show a poll in a .aspx page which is basic a question with 3 options & a button. Now on click of submit button i need to post the data to a dll & show the result from the dll itself. Any idea how to do this? is it possible..any code???

How WCF 4 REST Service Support Form Post As Well As XML and JSON?


Using the rest 4 template.  I have a POST method defined, with an object as a parameter.  REST 4 does a great job of automatically mapping both xml and json posts to the method.  I tested this using an HttpClient test application to build and post xml content and then json content. 

I want to also support a standard form post to the method but am having problems!  

I'd like the same method already accepting and converting both xml and json to also work correctly for a form post.  I am testing this by creating an HttpUrlEncoded form in the test client, adding form name/value pairs that match what the method is expecting, and trying to post it.

However I get a 400 Bad Request.  Here's some example code that is returning a 400 bad request:

            var client = new HttpClient();

            HttpUrlEncodedForm form = new HttpUrlEncodedForm();
            form.Add("Id", "99");
            form.Add("Message", "Message test with 'special' chars #!#");
            form.Add("IpAddress", "");

            var response = client.Post("<valid-uri-here>", form.CreateHttpContent());


need a way to post a form in my .aspx page to an external URL


I'm migrating an old ColdFusion site to ASP.NET. One of the pages has a form that posts to an external URL.

<form action='https://www.innlinkcrs.com/rescreate.asp' method='get'>

I just discovered that you can't do this in an .aspx page. Seems the page will just post to itself if you hit the submit button.

What's the proper technique for achieving this in ASP.NET? There are a couple of hidden fields that pass parameters to the external URL.


Ajax Post Form


Ok I have an interesting new assignment that I am trying to come up with the best solution for. Basically I have a web application that needs to provide access to another system from within a secured login, each application is at a different site. Basically the third party company that has the system I need to connect with wants me to access their site via a form post. This would typically not be a problem other than I need to have the option to connect from inside of pretty much every existing page withn the primary application. Each connection option will be some type of hyperlink that will then in turn target a new browser window to display the content from the third party. So obviously I cannot use the standard form post methods as the page form is already in use.

So my thought was to use Jquery Ajax Post, I use it all the time for typical Ajax functionality with other applications, but that is normally interaction with a webservice or webmethod. What I was thinking, is to create a post function to send all the required fields along to the third party company, without the need to actually create the form. Typically in the past when I have used this functionality I am returning some type of data that I just redisplay or interact with, but now I need to target a new browser and open the returned page. The third part

wcf 4 rest service accepts xml and json posts but get 400 bad request on form post


Using the rest 4 template.  I have a POST method defined, with an object as a parameter.  REST 4 does a great job of automatically mapping both xml and json posts to the method.  I tested this using an HttpClient test application to build and post xml content and then json content.  All data gets correctly mapped to the corresponding properties in my entity. 

I want to also support a standard form post to the method but am having problems! 

I'd like the same method already accepting and converting both xml and json to also work correctly for a form post.  I figured it would "just work" but no.

I am testing this by creating an HttpUrlEncoded form in the test client, adding form name/value pairs that match what the method is expecting, and trying to post it.

However I get a 400 Bad Request.  Here's some example code that is returning a 400 bad request:

Really straightforward but fails.  Ideas why? 


      var client = new HttpClient();

      HttpUrlEncodedForm form = new HttpUrlEncodedForm();
      form.Add("Id", "99"<

Run jQuery script after each form post in mvc2 app


I need to exec some js each time a page loads, and also every time a view is returned after a post action.  I use jQuery.ajax to post form - using url of Controller/Action.  Post is successful and response data is correct, but my js doesn't get called.

I had js in a script tag, within the head of my view.aspx, and found that it does not execute each time the response is received after a post action.  I also tried calling this within $(document).ready, but this does not execute after post action.  window.onload also does not exec after post action.

I prefer not to use MS AJAX js lib, but if there is some pageLoad function, I will give it a try.

Is there a native javascript event that is raised when http response is received?  Thanks.

Send model back when form post


public ActionResult DisplayView1()


  EmployeeModel myModel = new EmployeeModel();


  return View(myModel);


When I hit the sumit button on the view, that's method of the view is "post". How do I pass the original model back to the action?

<form id="employeeForm" name=employeeForm" action=<%Model.ActionName %> method="post">

<%Model.ActionName %> will be in this example equals "PostBackFromView"

I would like to have this:


public ActionResult PostBackFromView(EmployeeModel model)



What should I do in the view to enable the pass back of the model?


Search form post & results in MVC


Pls. pardon my ignorance. I have few questions based on following scenario:

I have a LoginController with following methods:

 public ActionResult Login()
        return View();

    public ActionResult Login(UserObject user)
     Calling Besiness Service to Validate User againts DB (Using Repository)... 

        if (success)
            return RedirectToAction("Search", "Search");
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
        return View(user);

After successful login, I have to present a Search screen. I have a SearchController with following methods:


Simulating Simple HTML form Post using HttpWebRequest..


Hi guys...

I have a problem posting xml Data using HttpWebRequest..

The server returns Internal error..

I want to simulate a simple Form with Method=Post. The form have three fields. Two for credentials and the third one for Posting XML. Here is the sample HTML which i want to simulate using HttpWebRequest..

<form action="https://myurl.com/samplepage.cfm" method="post" >
integration_id<input type="text" name="integration_id" value="id" /><br />
integration_pwd<input type="text" name="integration_pwd" value="pwd"  /><br />
<textarea name="hrxml" style="height: 404px; width: 593px">
<?xml version="1.0" encoding="UTF-8"?>
<BackgroundCheck account="test" userId="test" password="test">

How to post form with fields and binary file using ServerXMLHTTP?


I need to simulate user submitting a web form that contains some form fields and a binary file upload as part of the submit.  I found this KB: http://support.microsoft.com/kb/290591

But, that doesn't work with binary file.  Can someone provide an example of how to do it?



InfoPath Calculated Field doesn't Post to SharePoint List when form is submitted


I have a nice InfoPath form that includes a calculated total field.  That works great.   The form is published to a SharePoint list and when users of the form Submit the form to the list the form information neatly populates to the list.   Well, all of the fields populate to the list except for the calculated total field, that one is just blank.  Naturally, I've noodled around to figure out why and therefore I'm here now asking for guidance.   What should I be focusing on to resolve this issue?


How to post from a form to a Database and E-mail



I have a page up and running with a form that when you click submit it will either update the database (form action="") or forward you to a confirmation page (action=email.cshtml) both with method="post"

They both work on their own, it'll either update the database or successfully send out an e-mail, but not both which is what I need

How can I set this up so it will do both instead of one or the other?


JQuery Validate plugin to validate a ASP.NET Form

The first time I used the JQuery Validate plugin, it did not work at all, see JQuery Validate odd behaviour with the ASP.NET Script Manager for reason, but perseverance and stubbornness prevailed and I finally created my first JQuery validated ASP.NET Forms contact form.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend