How To Pass Data Between Two Pages In Asp.net
In this article i will show you different
processes to pass data between two pages in asp.net.
So for this article first you needed to create a
n asp.net web application. So the different precesses are as follows. You
can perform the operation on button click event.
suppose you have a label control and you are
siaplaying the value on it.
QUERYSTRING
For passing the value.
Response.Redirect("QueryStringPage.aspx?Data=" + YouValue);
For retriving.
Label1.Text=Request.QueryString["Data"].ToString();
SESSION STATE
For passing the value
Session["Data"] = YourValue;
Response.Redirect("SessionStatePage.aspx");
For retriving
Label1.Text=Session["Data"].ToString();
BY PUBLIC PROPERTY
For this define a public property
public string DataToSend
{
get
{
return yourvalue;
}
}
Now on button click redirect to other page.
Server.Transfer("PublicPropertiesPage.aspx");
For accessing the value
Lable1.Text=PreviousPage.DataToSend;
CONTEROL INFO:
Suppose you have a textbox in the page
<asp:TextBox ID="DataToSendTextBox" runat="server" Text="Dotnetpools.com"></asp:TextBox><br />
now on button click put the code
Server.Transfer("ControlInfoPage.aspx");
now on other page accessing the value
var textbox = PreviousPage.FindControl("DataToSendTextbox") as TextBox;
if (textbox != null)
{
Label.Text = textbox.Text;
}
No comments:
Post a Comment