Posting the Request to other ASP.Net Page


When you submit a request to an ASP.Net Page it will be posted to the same page. Whenever you need to post the request Other ASP.Net Page We need to use PostBackUrl Property of the ButtonControl. Here I will be giving an example to show How you can post the request to another ASP.Net Page.

Cross Page Posting - Overview


When you submit a request to an ASP.Net Page it will be posted to the same page. Whenever you need to post the request Other ASP.Net Page We need to use PostBackUrl Property of the ButtonControl. Here I will be giving an example to show how you can post the request to another ASP.Net Page.

Example for another ASP.Net Page


Step 1:
1. Create an ASP.Net Web Page with name post1.aspx
2. Use PostBackUrl Property of the button control to post the Request to another ASP.Net Page.

<html>
<head runat="server">
<title>Example: Posting the Data to Another ASP.Net Page</title>
</head>
<body>
<!-- Example for Cross Page Posting
PostBackUrl Property is used to post the data to another asp.net page
-->
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
<asp:Button ID="btnSend" runat="server" Text="Send" PostBackUrl="~/post2.aspx"/>
</div>
</form>
</body>
</html>

Step 2:
1. Create an ASP.Net page named "post2.aspx" to post the request.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Reading the data from First Post1.aspx page</title>
</head>
<body>
<!-- Example for Cross Page Posting -->
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> Welcome to New Session <br />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Post1.aspx">Back</asp:HyperLink>
</div>
</form>
</body>
</html>

Step 3:
1. Add the following code in the Page_Load Event of the "post2.aspx.cs" Code-Behind File.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class post2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
/* PreviousPage - Refers to the previous page which posted the data
FindControl - Used to refer to the Control in another page and it takes control name as a parameter.
*/
TextBox txt = (TextBox) PreviousPage.FindControl("txtName");
Label1.Text = txt.Text;
}
}

Note:
1. PreviousPage - Refers to the Previous page from where the request is posted.
2. FindControl - Method is used to identify the control in the Previous page.


Comments

Author: Gaurav Kumar Arora18 Apr 2012 Member Level: Gold   Points : 2

Hi Vijaya,

Nice to see the post, I am wondering how can I get the value with above example to third page.
Lets say I want to access BtnName value from current page to the third page's Text Box as follows:

1. From Page one I Submitted the name
2. Reach at page to by pressing BtnName from Page1
3. At page two I amended things with name
4. Now reached at Page 3 with this amendments
5. Now here I want to compare what was earlier on Page-1

Author: Vijayalakshmi G M19 Apr 2012 Member Level: Gold   Points : 0

Hi Gaurav,

Thanks for your comments.

I will work based on your suggestions and then update you.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: