我尝试从一个页面传递一些值到另一个页面,但在运行时我得到异常。即时通讯尝试从一个页面传递参数到另一个页面时获取NullReferenceException
这里是我的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.";
}
我得到这个异常:
异常详细信息:系统。 NullReferenceException:未将对象引用设置为对象的实例。
我以msdn为例。
为什么我会得到这个异常?
在哪一行你会得到NullReferenceException? – 2012-01-10 13:09:59