Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

Pawan Awasthi
More...


Resources » .NET programming » ASP.NET/Web Applications

Posting the Request to other ASP.Net Page


Posted Date:     Category: ASP.NET/Web Applications    
Author: Member Level: Gold    Points: 30


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.





Did you like this resource? Share it with your friends and show your love!


Responses to "Posting the Request to other ASP.Net Page"
Author: Gaurav Arora    18 Apr 2012Member 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 M    19 Apr 2012Member Level: Gold   Points : 0
Hi Gaurav,

Thanks for your comments.

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



Feedbacks      

Post Comment:




  • 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: .Net Mobile Development and Mobile Page Life Cycle
    Previous Resource: SEO Training institutes in Bangalore, India
    Return to Resources
    Post New Resource
    Category: ASP.NET/Web Applications


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Cross Page Posting  .  Posting a Request to another ASP.Net Page.  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.