IT-info > C#.NET

C#.NET

Formulärpyssel

Method: GET

form.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<form action="formfx.aspx" method="GET">
<p>string1 : <input type="text" name="string1"></p>
<p><input type="submit" value="PostMe"></p>
</form>
</body>
</html>

formfx.aspx:

<%
string testString = Request.QueryString["string1"];

Response.Write("<p>" + testString + "</p>");
%>

<%= "<p>" + Request.QueryString["string1"] + "</p>" %>

Method: POST

form.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<form action="formfx.aspx" method="POST">
<p>string1 : <input type="text" name="string1"></p>
<p><input type="submit" value="PostMe"></p>
</form>
</body>
</html>

formfx.aspx:

<%
//Request.QueryString("name");

string testString = Request.Form["string1"];

Response.Write("<p>" + testString + "</p>");
%>

<%= "<p>" + Request.Form["string1"] + "</p>" %>

<%
// The code below can be used to list all field names from a POSTed form

Response.Write("<p>");
string[] keys = Request.Form.AllKeys;
for (int i= 0; i < keys.Length; i++)
{
    Response.Write(keys[i] + ": " + Request.Form[keys[i]] + "<br>");
}
Response.Write("</p>");
%>

More info:
http://stackoverflow.com/questions/20151556/how-to-get-the-http-post-data-in-c