Pass Data Between ASP.NET Pages
There is the data to send in current page
<asp:TextBox ID="DataToSendTextBox" runat="server" Text="Hello World!"></asp:TextBox>
1.Use Query String
current page: Response.Redirect("QueryStringPage.aspx?Data=" + Server.UrlEncode(DataToSendTextBox.Text));
Redirect page: Server.UrlDecode(Request.QueryString["Data"])
2.Use HttpPost
current page:
<asp:Button ID="HttpPostButton" runat="server" Text="Use HttpPost"
PostBackUrl="~/HttpPostPage.aspx" />
PostBackUrl="~/HttpPostPage.aspx" />
Redirect page: Request.Form["DataToSendTextBox"]
3.Use Session State
current page:Session["Data"] = DataToSendTextBox.Text;
Redirect page:Session["Data"]
4.Use Public Properties
current page:
public string DataToSend
{
get
{
return DataToSendTextBox.Text;
}
}
{
get
{
return DataToSendTextBox.Text;
}
}
Server.Transfer("PublicPropertiesPage.aspx");
Redirect page:PreviousPage.DataToSend
5.Use Control Info
current page: Server.Transfer("ControlInfoPage.aspx");
Redirect page: var textbox = PreviousPage.FindControl("DataToSendTextbox") as TextBox;
something special