不能在aspx页面使用一项PostBackUrl时得到的值 [英] Not able to get values when using PostBackURL in aspx page
问题描述
我有一个文本框和一个按钮的页面。我已将这个按钮一项PostBackUrl并写了下面的code目的地网页的加载事件:
I have a page with a textbox and a button. I have set a postbackurl on this button and written the following code on the load event of destination page:
if (PreviousPage != null)
{
string name = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
Response.Write(name);
}
在使用调试器,我发现,我收到以下错误:
While using debugger, I found that I get following error:
Object reference not set to an instance of an object.
我无法找出问题的所在,因为当我徘徊在previousPage,我能看到第一页的名字,当我看到TextBox1中的值,它显示了 {系统。 Web.UI.WebControls.TextBox}
,而不是我所输入的数值!
I am not able to figure out where the problem is because when I hover on PreviousPage, I can see the first page name and when I see the value of TextBox1 it shows {System.Web.UI.WebControls.TextBox}
and not the value that I have entered!
推荐答案
我现在能够得到的文本框的值。使用带有母版页aspx页面的时候,我们需要首先得到的ContentPlaceHolder的引用,然后使用该引用来获得文本框的参考。
I am now able to get the value of textbox. when using a aspx page with a master page, we need to get the reference of the contentplaceholder first and then use that reference to get the reference of textbox.
ContentPlaceHolder Content1 =(ContentPlaceHolder)PreviousPage.Master.FindControl("MainContent");
TextBox SourceTextBox =
(TextBox)Content1.FindControl("TextBox1");
Response.Write(SourceTextBox.Text);
这将打印textbox.text的价值。
This will print the value of textbox.text.
这篇关于不能在aspx页面使用一项PostBackUrl时得到的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!