tags:

views:

588

answers:

2

-Edit- Jon Skeet and darin togther answered my question 100%

I am trying to get POST data but i have no luck whatsoever. By 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.

Test.cs

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"; }
}

Default.aspx

<%@ 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"&gt;

<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>
+3  A: 

Have you tried 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.

Jon Skeet
+1  A: 

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" />
Darin Dimitrov
Thats what i did wrong! thanks.
acidzombie24