Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

asp.net form method confusion

Hi,

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
Page_Load(....)
{
   // 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 ?
0
mrwad99
Asked:
mrwad99
1 Solution
 
RiverGuyCommented:
What is supposed to happen after the user submits an entry....refreshes the guestbook, or takes him to his entry in it, or what?
0
 
DiRNCommented:
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.
0
 
tomvergoteCommented:
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mrwad99Author Commented:
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 ?
0
 
tomvergoteCommented:
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.

eg:
- 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
0
 
mrwad99Author Commented:
Thanks tomvergote for clarifying this confusion, and also to everyone else who provided feedback.  It is much appreciated.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now