Я пытаюсь передать какое-то значение с одной страницы на другую, но во время выполнения я получаю исключение.
Вот мой ASP-код:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
Enter a value to post:
<asp:textbox id="TextBox1"
runat="Server">
</asp:textbox>
<br /><br />
<asp:button id="Button1"
text="Post back to this page"
runat="Server">
</asp:button>
<br /><br />
<asp:button id="Button2"
text="Post value to another page"
postbackurl="Button.PostBackUrlPage2cs.aspx"
runat="Server">
</asp:button>
</asp:Content>
Вот код нацелевая страница:
void Page_Load(object sender, System.EventArgs e)
{
string text;
// Get the value of TextBox1 from the page that
// posted to this page.
text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
// Check for an empty string.
if (text != "")
PostedLabel.Text = "The string posted from the previous page is "
+ text + ".";
else
PostedLabel.Text = "An empty string was posted from the previous page.";
}
Я получаю это исключение:
Сведения об исключении: System.NullReferenceException: ссылка на объект не установлена на экземпляр объекта.
Я взял пример из msdn .
Почему я получаю это исключение?