Решил проблему так:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="WebAppSendMessage.Views.Index" %>
<asp:Content ID="header" ContentPlaceHolderID="head" runat="server">
<style>
input[type=text] {
margin-top: 5px;
margin-left: 3px;
margin-right: 3px;
width: 100%;
}
input[type=submit] {
margin-top: 5px;
margin-left: 3px;
margin-right: 3px;
}
</style>
</asp:Content>
<asp:Content ID="mainContent" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<form id="mainForm" method="post" runat="server">
<asp:TextBox ID="textBox" runat="server" />
<br />
<asp:Button ID="sendMessageButton" runat="server" Text="Отправить сообщение" OnClick="SendMessageButton_OnClick"/>
</form>
</asp:Content>
using System;
using System.Web;
using System.Web.UI;
namespace WebAppSendMessage.Views
{
public partial class Index : Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies["mainMessage"];
if (cookie != null)
{
string message = cookie["Message"];
if (message != null)
{
textBox.Text = message;
}
}
}
protected void SendMessageButton_OnClick(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies["mainMessage"];
if (cookie == null)
{
cookie = new HttpCookie("mainMessage");
cookie.Expires = DateTime.Now.AddYears(1);
}
string message = Request.Form[textBox.UniqueID];
cookie["Message"] = message;
Session["Message"] = message;
Session["BackAddress"] = Request.RawUrl;
Response.Charset = "utf-8";
Response.Cookies.Add(cookie);
Response.Redirect("Message.aspx");
}
}
}
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true"
CodeBehind="Message.aspx.cs" Inherits="WebAppSendMessage.Views.Message" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<form id="mainForm" runat="server">
<asp:Label runat="server" Text="<%# Text %>"></asp:Label>
<br />
<asp:Button ID="backButton" runat="server" Text="Вернуться" OnClick="GoToBackButton_OnClick" />
</form>
</asp:Content>
using System;
using System.Web;
using System.Web.UI;
namespace WebAppSendMessage.Views
{
public partial class Message : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataBind();
}
}
protected string Text
{
get { return (string)Session["Message"]; }
}
protected void GoToBackButton_OnClick(object sender, EventArgs e)
{
string returnUrl = Session["BackAddress"] as string ?? "Index.aspx";
Response.Redirect(returnUrl);
}
}
}