asp.net form method confusion

Posted on 2003-03-28
Medium Priority
Last Modified: 2010-04-15

I am writing a web page that allows the user to add a comment to a guestbook.  Easy.  What I am doing at the minute is simply running a _Click handler for my submit button that proceeds to open up a database connection and insert the new data.  Once again easy.

However, with this method I cannot see the point in using FORM METHOD and ACTION specifiers.  The only possible cause I can see to use FORM ACTION is to specify the name of the current script and then handle the parameters passed to it in the Page_Load method, eg

// Within thisScript.aspx
   // Handle data from the query string with Request.QueryString(["<data parameter name>"])
<form METHOD=post ACTION=thisScript.aspx?<data parameters> >

However this is questionable as how would the data parameters be passed into the action tag when this is static HTML?  Obviously a _Click handler could redirect (Repsonse.Redirect) the page to itself with the new data parameters that would be handled in Page_Load(), but then there would be no need for the FORM ACTION tag !

Can someone clarify the purpose of forms and end this confusion ?
Question by:mrwad99
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8226987
What is supposed to happen after the user submits an entry....refreshes the guestbook, or takes him to his entry in it, or what?

Expert Comment

ID: 8227100
The <form> tag would look like:
<form METHOD=post ACTION=somescript.aspx>

Clicking a submit button (<input TYPE=submit>) would cause the information to be sent to somescript.aspx as part of the Request header (as opposed to as part of the URL if get is specified).

In your case, your assumption about causing the page to submit itself to itself is correct.  In most situations (i.e., not .NET sites), however, this is how forms work, as there are no event handlers associated with the page.  In these situations, the METHOD attribute would be used to specify how the information is to be sent and the ACTION attribute is used to specify the page that will handle to information entered into the form.

For example, MSN uses the following code for their search engine:
<form id="searchweb" action="1/0/default.asp" method="get">

This code submits the form information to 1/0/default.asp where it is handled.

Expert Comment

ID: 8244105
why would you try that?

wouldn't it be a whole lot easier to just create some hidden fields for your parameters (the ones you are trying to send through the querystring), and updating those hidden field's values through code. Then if you post back the form, all your data will be in the postback

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 19

Author Comment

ID: 8274640
Sorry about the delay all.

I am still unclear on the differences between running a button handler and using the form method/action tags.

In general which should be used and in which situation ?

Accepted Solution

tomvergote earned 120 total points
ID: 8281930
in general:
unless you NEED to post your form to something else than the webform itself (called postback) you would always use the form's event handlers.

- you need to post the form to a downloaded cgi script, or a script on another server: use the action (and don't let the form be runat="server"
- otherwise: use the runat="server" attribute and use the button_onclick etc... event handlers
LVL 19

Author Comment

ID: 8282561
Thanks tomvergote for clarifying this confusion, and also to everyone else who provided feedback.  It is much appreciated.

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question