0

I'm pulling my hair out. I can't get this simple thing to work. I can't get the values from POST? What's the trick to reading POST values within aspx pages.

Here is the html page.

                <html>
                <head>
                </head>
                <body>
                    <form id="frm_post" action="default.aspx" method="POST">
                    <table>
                        <tr>
                            <td>
                                Name 2:
                            </td>
                            <td>
                                <input type="text" id="txtName2″" name="name2″" value="Jack" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Address 2:
                            </td>
                            <td>
                                <input type="text" id="txtAddr2″" name="addr2″" value="Oz" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                            </td>
                            <td>
                                <input type="submit" value="Send Using Post" />
                            </td>
                        </tr>
                    </table>
                    </form>
                </body>
                </html>

Here is my aspx pge

            protected void Page_Load(object sender, EventArgs e)
            {


                if (Request.HttpMethod == "POST")
                {
                    string text = Request.Form["name2"];
                    Response.Output.WriteLine(text);
                }

            }
  • so action of your HTML page is set to aspx page with method set to POST? did you try...Response.write(text)? try commenting out the IF statement. – highwingers Nov 20 '13 at 21:19
  • http://stackoverflow.com/questions/564289/read-post-data-submitted-to-asp-net-form – mehdi Nov 20 '13 at 21:22

2 Answers2

0

something like this...

NameValueCollection nvc = Request.Form;
string userName, password;
if (!string.IsNullOrEmpty(nvc["txtUserName"]))
{
  userName = nvc["txtUserName"];
}

if (!string.IsNullOrEmpty(nvc["txtPassword"]))
{
  password = nvc["txtPassword"];
}
highwingers
  • 1,649
  • 4
  • 21
  • 39
0

There's an extra double quote character on your field ID and name values.

<td>
    <input type="text" id="txtName2″" name="name2″" value="Jack" />
</td>

Should be

<td>
    <input type="text" id="txtName2" name="name2" value="Jack" />
</td>

The same happens to your txtAddr2 field. As the saying goes, 'The Devil is in the detail'.

OnoSendai
  • 3,960
  • 2
  • 22
  • 46
  • That looks like it was the problem. I copied the code form a website and seams like something got corrupt because the double quotes kept coming back after saving the file. –  Nov 20 '13 at 21:46