Read, With the Name of Your Lord Who Created

Posts Tagged ‘HTTP Post’

Interacting With Get and Post Methods in ASP.NET

Posted by triaslama on May 1, 2008

There are two common ways to pass data from one page to another, using http Get and Post methods. In Get method, data passed to server using URL encoding. So with Get method data added in URL as query string. For more information on how to retrieve query string values, you can read my previous post here. When we use Post method the URL is still intact, because data passed in HTTP body.

In correlation with ASP.NET, retrieving data passed through HTTP Get and Post methods is quite simple. If data passed with Get method we need the following code to retrieve the data:

Page.Request.QueryString[<param>];

If data passed with Post method we need the following code to retrieve the data:

Page.Request.Form[<param>];

Maybe the problem will more suitable addressed with hand in code practice, so let’s try a simple code! I named the HTML file as methods_source.htm:

    <html>
    <head>
    <title>Using Http Get And Post</title>
    </head>
    <body>
    <form id=”frm_get” action=”get_recv.aspx” target=”_blank” method=”GET” >
    <table>
    <tr>
    <td>Name: </td> <td><input type=”text” id=”txtName” name=”name” /></td>
    </tr>
    <tr>
    <td>Address: </td> <td><input type=”text” id=”txtAddr” name=”addr” /></td>
    </tr>
    <tr>
    <td></td> <td><input type=”submit” value=”Send Using Get” /></td>
    </tr>
    </table>
    </form>
    <p />
    <form id=”frm_post” action=”post_recv.aspx” target=”_blank” method=”POST” >
    <table>
    <tr>
    <td>Name 2: </td>
    <td><input type=”text” id=”txtName2″ name=”name2″ /> </td>
    </tr>
    <tr>
    <td>Address 2: </td>
    <td><input type=”text” id=”txtAddr2″ name=”addr2″ /> </td>
    </tr>
    <tr>
    <td></td>
    <td><input type=”submit” value=”Send Using Post” /> </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

Read the rest of this entry »

Posted in .NET, ASP.NET | Tagged: , , , , | 82 Comments »