I have the following HTML/ASP.NET code:
<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" method="post">
Name: <input type="text" id="navn" runat="server"/>
<input type="submit" id="submit" value="Submit!" runat="server" />
<input type="reset" />
<br />
<%if (Request.Form["submit"] != null)
{
Response.Write("<br/>");
Response.Write("Submit button pushed");
}
if (Request.Form["navn"] != null && Request.Form["navn"] != "")
{
Response.Write("<br/>");
Response.Write("Name OK");
}
%>
</form>
</body>
</html>
When using the “POST” form post method I get the following output:
Submit button pushed
Name OK
When using the “GET” form post method NOTHING is printed out?!
Request.Formcontains information that is sent usingPOST. When you useGETthe information will be in theRequest.QueryStringcollection. In your case this means thatRequest.Form["submit"]isnull.If you want to support both then you would be able to use the
Request.Itemcollection which includes values from:Request.CookiesRequest.FormRequest.QueryStringRequest.ServerVariablesHowever, doing this you may get some unexpected results if you use a parameter name that is used in one of the other collections.