using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class ResultsPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
string username = ((TextBox)PreviousPage.FindControl("usename")).Text;
string passward = ((TextBox)PreviousPage.FindControl("passward")).Text; // labelResult.Text = String.Format("{0} {1}", usename, passward);
}
catch(Exception a)
{
labelResult.Text = a.ToString();
} /*catch
{
labelResult.Text = "It's Wrong!";
}*/
}
}调试至红色的语句,捕获错误"System.NullReferenceException: 未将对象引用设置到对象的实例。 在 ResultsPage.Page_Load(Object sender, EventArgs e) 位置 c:\Users\yuanhuihua\Documents\Visual Studio 2010\WebSites\EventRegistrationWeb\ResultsPage.aspx.cs:行号 15".
求大侠指教!在线等。
解决方案 »
- html控件怎么进入事件?
- 怎么用remote site
- 如何用GRIDVIEW做链接实现新闻标题列表到新闻详细内容的跳转
- 求,简单的用户在线显示用户列表在线等,急急
- winFrom程序里面的DataGrid导出到Excel
- .net程序出错了,知道的朋友快进来帮我看看.
- 大家有没有考虑过如何保护自己的版权信息呢?
- .NET连接SQLSERVER2005的连接窜怎么写?
- sessionState中的TimeOut在服务器上设置不起作用
- 怎样动态的管理DataGrid的列?怎样用一个Css文件管理DataGrid的样式?
- asp.net查询datatable数据时返回无法找到数据库的表
- 急!求asp.net网页上不用数据绑定控件绑定绑定数据呈现
TextBox tb=(TextBox)PreviousPage.FindControl("usename");
string username = tb.Text;页面传值的方法很多啊,参考http://www.cnblogs.com/liukemng/archive/2010/12/04/1895966.html
<@ PreviousPageType VirtualPath="~A.aspx" %>
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
}原页面应该没有什么代码的。
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="label" runat="server" Text="Label"></asp:Label>
</div>
<a href="source.aspx">source.aspx</a>
</form>
</body>
</html>source.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="source.aspx.cs" Inherits="source" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="dropDownList" runat="server">
<asp:ListItem>A is a</asp:ListItem>
<asp:ListItem>B is b</asp:ListItem>
<asp:ListItem>C is c</asp:ListItem>
</asp:DropDownList>
<br />
<asp:TextBox ID="username" runat="server"></asp:TextBox>
<br />
<asp:Button ID="SubmitButton" runat="server" PostBackUrl="~/a.aspx"
Text="Submit" />
</div>
</form>
</body>
</html>
在线坐等大侠指点啊!
Server.Transfer()跳转页面的在另一个页面后台跳转要这样写,Server.Transfer("ResultsPage.aspx");
string passward = Request.Form["username"]看看
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class source : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Server.Transfer("a.aspx");
}
}您说是加在那个地方么,运行之后,那个错误依然没有解决。
源页面 HTML部分:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="THJS.JxBuilder.Web.WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="test" runat="server" ></asp:TextBox>
<asp:Button runat="server" ID="testButton" Text="提交" PostBackUrl="~/WebForm2.aspx" />
</div>
</form>
</body>
</html>源页面 cs部分:没写任何代码
目标页 HTML部分:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="THJS.JxBuilder.Web.WebForm2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="testLable" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
目标页 cs部分:using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;namespace THJS.JxBuilder.Web
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
testLable.Text = ((TextBox)Page.PreviousPage.FindControl("test")).Text;
}
}
}
}
非要搞什么FindControl
直接把你的连接这么写不就完了?Server.Transfer("a.aspx?username ="+你要穿的值,比如username);
然后另一个界面获取
string username = Resqurest.QueryString["username"].ToString();
这样就能获取了
http://blog.csdn.net/learnren/article/details/4075508
最后谢谢大家了。