Post Method - Example Code

Posted by Venkat | Labels: ,

Here I am going show : how to post the data from one page to another page using POST Method.

Here is the Simple example.

P1.aspx


   <form id="form1" runat="server" method ="post" action ="p2.aspx">
    <div>
    User : <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br/>
        Password : <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>

        <asp:Button ID="btnSend" runat="server" Text="Send"  PostBackUrl ="~/p2.aspx" /> 
    </div>
    </form>



So if you are going to use post method on form tag set method="post" and action="p2.aspx" ie: designation url to get the data of p1.aspx on p2.aspx.

P2.aspx


 <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </div>
    </form>





protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Text = Request.Form["txtName"].ToString ();
        TextBox2.Text = Request.Form["txtPassword"].ToString ();
    }


Finally on destination page

using Request.Form["yourcontrolid"] to get value of the control on p1.aspx

PayOffers.in