2

What is the default form HTTP method?

As stated in the link above an everywhere else the default posting method used in HTML forms is GET but I seem to get the POST methods results when NOT including the method="" attribute in my form declaration:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Ny test</title>
    <link rel="stylesheet" type="text/css" href="StyleSheet.css" />
</head>
<body>

    <form action="Default.aspx" runat="server">

    Name: <input type="text" id="navn" runat="server"/>
    <input type="submit" id="submit" value="Submit!" runat="server" />
    <input type="reset" />
    <br />

    </form>
</body>
</html>

The HTML code above results in the following output in the URL after the submit button is clicked:

http://localhost:62733/WebSiteTest/Default.aspx

When explicitly using the "GET" method attribute I get the following output in the URL after the submit button is clicked:

http://localhost:62733/WebSiteTest/Default.aspx?__VIEWSTATE=%2FwEPDwULLTE4OTM2NjcwNTBkZIRLV0rUSQgWDDv1sI1c1b%2Fj3fJXcWYiESG%2FlBGieAM4&__EVENTVALIDATION=%2FwEWAwK3qIiCDgK%2B2K%2BHBgLcu4S2BHrznTBZeKNNwWHoyMUQHB9lYE%2B7CEDwuP5UEvN7ULBt&navn=&submit=Submit%21"

Why is this happening? Default posting method for HTML forms is GET, so why I am getting the opposite results when not including GET as the method attribute?

Is this Visual Studio/ASP.NET defaulting to the POST method in HTML forms?

Community
  • 1
  • 1
Birdman
  • 5,244
  • 11
  • 44
  • 65
  • The better question is why aren't you just defining the method to get your expected results 100% of the time? – MetalFrog Dec 16 '11 at 12:51

1 Answers1

2

ASP.Net sets the method to POST for the form. I assume so that button presses result in POST requests which is more semantic than a GET and to prevent very long urls with the viewdata in the querystring.

Check your HTML source and you will see the method="post" attribute.

detaylor
  • 7,112
  • 1
  • 27
  • 46