本文介绍了我尝试将参数从一页传递到另一页时发生NullReferenceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果您能帮助我解决问题,我将不胜感激.您好,我尝试将某些值从一页传递到另一页,但在运行时出现异常.
这是我的ASP代码:
I would be grateful if you could help me to solve the problem. Hello I try to pass some value from one page to another but at the run time i get exception.
Here is my ASP code:
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="PostBackUrlPage2cs.aspx" runat="Server">
</asp:button>
以下是目标页面上的代码:
Here''s the code-behind on the destination page:
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.";
}
我收到此异常:
I get this Exception:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
我以msdn为例:
为什么会出现此异常?如何解决此问题?
预先谢谢您.
I took the example from msdn:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.postbackurl.aspx
Why do I get this exception?and how can I solve this problem?
Thank you in advance.
推荐答案
这篇关于我尝试将参数从一页传递到另一页时发生NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!