Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I retrieve HTML POST data for manipulation in ASP.NET WebForms?

I have the following html:

<html>
    <body>

        <form runat="server">
        Name: <input type="text" name="name" />
        <br />
        <input type="submit" name="submit" />
        </form>

    </body>
</html>

How do I retrieve the value in the "name" textbox posted back to the webserver to manipulate in ASP.NET WebForms?

(I know about the ASP.NET built-in controls and the possibilities with them, but I am looking for a "clean" solution without the use of built-in ASP.NET controls)

like image 598
Birdman Avatar asked Dec 14 '11 15:12

Birdman


2 Answers

If you can't, or don't want to use asp.net textboxes, then you can retrieve the name of a regular html textbox like this:

string nameTextPosted = Request.Form["name"];

Just note that textboxes created in this manner will not automatically persist their values across postbacks like asp.net textboxes will.

like image 174
Adam Rackis Avatar answered Nov 10 '22 17:11

Adam Rackis


Simplest solution would be to turn it into a server-side component and access it by it's name. e.g.

<asp:TextBox Id="Name" runat="server"></asp:TextBox>

...

string name = Name.Text;

Unless you have other reasons not to use a component, you'd only be making things much more difficult on your part for no justification.

like image 4
George Johnston Avatar answered Nov 10 '22 16:11

George Johnston