从一个.Net页面获取价值 [英] Get value from one .Net page to another

查看:57
本文介绍了从一个.Net页面获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Default.aspx页面中有一个文本框(id =TextBox1)。我想从Default2.aspx页面获取textbox1的值



protected void Button1_Click(object sender,EventArgs e)

{



TextBox tb =(TextBox)PreviousPage.FindControl(& quot; TextBox1& quot;);

if(tb!= null)

{

Label1.Text = tb.Text;

}

}

当我单击按钮时出现错误:





描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。



异常详细信息:System.NullReferenceException:对象引用未设置为实例一个对象。



来源错误:





第30行:/ / page_load();

第31行://Label1.Text = PreviousPage.Name;

第32行:TextBox tb =(TextBox)PreviousPage.FindControl(TextBox1 ); if(tb!= null)

第33行:{

第34行:Label1.Text = tb.Text;

解决方案

你好。

首先我建议你添加一个标签ASP .NET。

其次如果你想在页面之间交换数据,你应该考虑填写GET或者您的请求或/和/或添加会话的信息。

以下链接可能会有所帮助

http://msdn.microsoft.com/en-us/library/6c3yckfw(v = VS.100)的.aspx [< a href =http://msdn.microsoft.com/en-us/library/6c3yckfw(v=vs.100).aspx\"target =_ blanktitle =New Window> ^ ]

http://code.msdn.microsoft.com/How -to-Pass-Data-Between-935838e4 [ ^ ]

http://aspdotnetfaq.com/Faq/How-to-make-Cross-Page-Postback-in-ASP -Net.aspx [ ^ ]

http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/5-ways-to-send-data-between-Asp-Net-pages/ [ ^ ]

There is a textbox (id="TextBox1") in Default.aspx page. I want to get the value of the textbox1 from Default2.aspx page

protected void Button1_Click(object sender, EventArgs e)
{

TextBox tb = (TextBox)PreviousPage.FindControl(&quot;TextBox1&quot;);
if (tb != null)
{
Label1.Text = tb.Text;
}
}
When I click the button it arises an error :


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 30: //page_load();
Line 31: //Label1.Text = PreviousPage.Name;
Line 32: TextBox tb = (TextBox)PreviousPage.FindControl("TextBox1"); if (tb != null)
Line 33: {
Line 34: Label1.Text = tb.Text;

解决方案

Hi.
Firstly I suggest you to add a tag ASP .NET.
Secondly if you want to exchange data between pages you should consider to fill GET or POST insformation with your request or/and to add session.
The following links might be helpful
http://msdn.microsoft.com/en-us/library/6c3yckfw(v=vs.100).aspx[^]
http://code.msdn.microsoft.com/How-to-Pass-Data-Between-935838e4[^]
http://aspdotnetfaq.com/Faq/How-to-make-Cross-Page-Postback-in-ASP-Net.aspx[^]
http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/5-ways-to-send-data-between-Asp-Net-pages/[^]


这篇关于从一个.Net页面获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆