Cross page posting, Submit Form and Server.Transfer methods in ASP .NET for data transfer

Posted by in ASP.NET category on for Beginner level | Views : 21238 red flag

To transer data using cross page posting, we need to use FindControl method. We can write code like this
Please read my previous article to know about other ways of transferring data from one page to another at
Cross page posting in ASP.NET
First of all we need to set the PostBackUrl property of the Button we are gonna use for postback, to the page where we need to redirect, in our case it's Default2.aspx

To retrieve the value of a textbox from previous page in Default2.aspx page, we need to use FindControl method to find the textbox control of previous page

TextBox txtName = (TextBox)PreviousPage.FindControl("txtUserName"));

lblName.text = txtName.Text.ToString();

Submit Form Method
To post data and retrieve on another page in ASP.NET, to start with simplest method we can write code like this

<form id="form1" method="post" 
Data <input type="text"
="Data" size="20"><br>

<input id="Submit1" type="submit"
="submit" />

And to retrieve it on the posted page

lblValue.Text = Request.Form["Data"];

ASP.NET does not support post method with runat="Server" attribute, for this we will have to use javascript
<form id="Form1" method="post"
<asp:TextBox ID="txtData" runat="server">

<form name="FormSubmit" action="Default2.aspx"
<input id="Submit1" type="submit"
onclick="CopyTextToHiddenField()" />
<input name="Hidden1" type="hidden" />

Add this JavaScript in the Head section of page to be posted.

<script language="javascript">
function CopyTextToHiddenField()
var textbox1Value = document.getElementById

("Hidden1").value = textbox1Value;

To retrieve the value of hidden field in Default2.aspx page

lblData.Text = Request.Form["Hidden1"];
Server.Transfer Method
Server.Transfer method sends (transfers) all the state information all application/session variables and all items in the request collections) created in one ASPX page to a second ASPX page.

You can't use Server.Transfer to send the user to an external site.

The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.

For example, if your Default.aspx has a TextBox control called TextBox1 and you transferred to Default2.aspx with the preserveForm parameter set to True, you'd be able to retrieve the value of the original page TextBox control by referencing Request.Form("TextBox1").

protected void Button1_Click1(object sender, EventArgs e)
Server.Transfer("Default2.aspx", true);

Now in Default2.aspx page_load event use the below code to get the value of TextBox1



Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: amiT jaiN
Member Level: Starter
Member Status: Member
Member Since: 12/26/2008 7:19:35 AM

Login to vote for this post.

Comments or Responses

Posted by: Ashwnk on: 12/17/2018 | Points: 25
Thank you so much admin for making this important Online tutorial, am going to learn with this about synchronization process of windows 10 computer system.

Login to post response

Comment using Facebook(Author doesn't get notification)