.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

Help with form input and post

Posted By:      Posted Date: August 23, 2010    Points: 0   Category :ASP.Net

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

View Complete Post

More Related Resource Links

Validate form input - Japanese


 I've searched for several hours and haven't come up with a reference - or even many discussions - of how to go about validating Japanese names, addresses, etc. When I lived in Japan websites, atm's etc. required such info to be entered with the roman alphabet but I've seen some websites that are allowing Kanji/Hiragana/Katakana. I haven't tested many of them for validation but one that I did test (after looking at the page source and discovering no client-side validation) allowed me to put this in the name field: J*=123*go^ Neat!

Any pointers/references? Thanks

Enabling/disabling input controls in a form

I am writing a ASP.NET UserControl and I am trying to incorporate JQuery into this.
The control is a simple form with a few input fields (text, checkbox, select, radio).
The first element in the form is a checkbox. Upon clicking this checkbox I want the all the input elements in the form (except the checkbox control itself) to be enable/disable. I tried writing some of this code but my solution was not getting me anywhere.
Below is the ASP.NET form code. I'd appreciate the help with some code or pointers into what I am doing wrong.
 <asp:Panel ID="pnlInputControls" runat="server">
    <table style="width:100%;">
            <td style="width:50%">
                <asp:CheckBox ID="chkBenefitName" runat="server" Checked="true" TextAlign="Right" ClientIDMode="AutoID" style="padding:0 0 0

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.  

Form input to output as a link on the display page (need help please)

 I have a form, the form works great and displays the information perfectly on a designated display page I have set up from its database.  One problem, I want to display it as a link to the site instead of how it is now, just plain text. Thus the user would put in the text box the site and hit submit and the site would appear of the display page.  Can anyone please assist me on this, and where to drop the hyperlink control? in the form page? or in the display page?    Below is my form code page:     <p><strong><font face="Verdana, Arial, Helvetica, sans-serif">International Access Entry      Form</font></strong></p><p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Please enter information      international contact information below. This if for authorized staff only.</font></p><table width="548" border="0" cellpadding="0" cellspacing="10" bgcolor="f0f0f0">  <tr>    <td width="528"><form name="INTL_Form" method="post" action="INTL-results.asp">      <p><font face="Verdana, Arial, Helvetica, sans-serif"> </f

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???

I don't want Form to Post with ENTER key

 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

WPF: Recreating a paper form as an online application for data input/retrieval: 2 problems


As with many paper forms,

(1) I have a form with some one-character-per-box data entry fields.

How could I implement the same thing using WPF?

(2) I also have some multi-line data entry fields--some of which begin in the middle of a row, but continue at the beginning of the next row.

Any ideas as to how to set my application up so that these rows can be merged into one field?

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"<

Using a sharepoint list to populate a form then capture user input


Hi.  New to this forum but looks like a great resource.  I am using MOSS2007, Infopath 2007 and Nintex workflow 2007.

I have a form that will act as a report for each of the operational sites in my company.  Each site receives freight movements on a daily basis and these are on a schedule; I am trying to record the variances to that schedule.  What I have attempted to do is the following:

  • Create a sharepoint list that contains each of the scheduled arrivals per site.
  • Connect to this list in Infopath as a secodary data source.
  • Drop this in to the form as a repeating table.
  • Filter the list of arrivals by using the conditional formatting control on the section, bound to a drop-list where the user specifies the facility/site.

What I am trying to do is present these arrivals and have the user enter an "actual" arrival time next to each, then store the results on submit.  I therefore need to know two things, 1) how to capture an "actual" value for each row in the repeating table (at the moment this is pulled in as an empty field from the list) and 2) how to store the data on submit so it is there when the form is re-opened.

I hope this makes sense, happy to give you any further information that may be required.

Thanks, Matt

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.

take input form external hardware via USB


can u please tell me how should i take input from external device by using c# application???

for eg. i want to capture input from biometric device in my new application so for this how should i connect my application with this hardware????

can u please guide me.


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:


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