当初是html 页面向aspx 页面传参数,说的是未将对象引用设置到对象的实例。 可是现在用aspx向aspx页面传递参数,还是说的是
未将对象引用设置到对象的实例。 郁闷啊,
html 向aspx传递参数没有正确是因为 name属性没有写正确
那aspx向aspx传递参数又是哪里不正确呢!!1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="1.aspx.cs" Inherits="_Default" Debug="true"%>
<!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="t1" runat="server" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>1.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("2.aspx");
}
}2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="2.aspx.cs" Inherits="Default2" %>
<!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>
</div>
</form>
</body>
</html>
2.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string aa=Request.Form["t1"].ToString();
Response.Write(aa);
}
}
当然收不到值.
如果要传递可以用.
Response.Redirect("2.aspx?t1="+t1.Text);然后在2中string aa=Request.QueryString["t1"];
string aa=Request.Form["t1"]==null?"":Request.Form["t1"].ToString();
1、使用明文串:2.aspx?name=XXX,在第二个页面中再分析;
2、使用页面投递,个人认为这是不错的选择,因为复杂的值传递也很麻烦,比如时间一类的:在1.aspx中写属性:
public string t1_value
{
get{return t1.text;}
}2.aspx中写:
<%@ PreviousPageType VirtualPath="~/1.aspx" %>cs页面的Load:
if (!Page.IsPostBack)
{
if (PreviousPage != null)
{
string _str = PreviousPage.t1_value;
}}
Response.Redirect("2.aspx");
改为:
Server.Transfer("2.aspx");