I am trying to get POST data, but I'm having no luck. My code is below. When I click the form button nothing happens.
I expected at least my IDE to snap at A.Ret(), but nothing happens whatsoever.
using System.Web;
public class A
{
    public static string ret() {
        var c = HttpContext.Current;
        var v = c.Request.QueryString; // <-- I can see get data in this
        return c.Request.UserAgent.ToString();
        return c.Request.UserHostAddress.ToString();
        return "woot";
    }
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="aspnetCSone._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server" method="post" action="Default.aspx">
            <input type=hidden name="AP" value="99" />
            <input type=button value="Submit" />
            <div>
                <a id="aa">a</a>
                <% = A.ret() %>
            </div>
        </form>
    </body>
</html>
Try using:
string ap = c.Request["AP"];
That reads from the cookies, form, query string or server variables.
Alternatively:
string ap = c.Request.Form["AP"];
to just read from the form's data.
c.Request["AP"] will read posted values. Also you need to use a submit button to post the form:
<input type="submit" value="Submit" />
instead of
<input type=button value="Submit" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With