请问大神一个问题,希望大神解答using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace builtInObject
{
public partial class SendMessage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void QueryString_Button_Click(object sender, EventArgs e)
{
Response.Redirect("http://localhost:1934/QueryString.aspx?TextBox1=" + TextBox1.Text + "&TextBox2=" + TextBox2.Text);
}
protected void Session_Button_Click(object sender, EventArgs e)
{
Session["TextBox1"] = TextBox1.Text;
Session["TextBox2"] = TextBox2.Text;
Response.Redirect("Session.aspx");
}
protected void ServerTransfer_Button_Click(object sender, EventArgs e)
{
Server.Transfer("ServerTransfer.aspx?TextBox1=" + TextBox1.Text + "&TextBox2=" + TextBox2.Text);
}
public string userName
{
get { return this.TextBox1.Text; }
set { this.TextBox1.Text = value; }
}
public string userCode
{
get { return this.TextBox2.Text; }
set { this.TextBox2.Text = value; }
}
protected void PreviousPage_Button_Click(object sender, EventArgs e)
{
Response.Redirect("PreviousPage.aspx");
}
}
}这是asp的web编程的发送代码;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace builtInObject
{
public partial class PreviousPage : System.Web.UI.Page
{
// SendMessage sendPage;
protected void Page_Load(object sender, EventArgs e)
{
SendMessage sendPage = (SendMessage)Context.Handler;
Response.Write(sendPage.userName + "<div  ></div>" + sendPage.userCode);
}
}
}这是接收页面代码;“/”应用程序中的服务器错误。
无法将类型为“ASP.previouspage_aspx”的对象强制转换为类型“builtInObject.SendMessage”。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidCastException: 无法将类型为“ASP.previouspage_aspx”的对象强制转换为类型“builtInObject.SendMessage”。
源错误:
行 13: protected void Page_Load(object sender, EventArgs e)
行 14: {
行 15: SendMessage sendPage = (SendMessage)Context.Handler;
行 16:
行 17: Response.Write(sendPage.userName + "<div  ></div>" + sendPage.userCode);
源文件: d:\Program Files\我的文档\Visual Studio 2013\Projects\builtInObjectSolution\builtInObject\PreviousPage.aspx.cs 行: 15
堆栈跟踪:
[InvalidCastException: 无法将类型为“ASP.previouspage_aspx”的对象强制转换为类型“builtInObject.SendMessage”。]
builtInObject.PreviousPage.Page_Load(Object sender, EventArgs e) in d:\Program Files\我的文档\Visual Studio 2013\Projects\builtInObjectSolution\builtInObject\PreviousPage.aspx.cs:15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772这是错误信息,求解决?
使用 Server.Transfer
完美解决,谢谢!初学,希望多多指教!
帮我看一下,怎么才能让“使用PreviousPage方式传递”不下移位于网页body顶部
@FLYINGSNOWGO: 调Response.Write 输出循序或使用JS移动
@Yu: 好吧!在接收端加入了2个label控件,然后用它来接收传过来的值,这样简单点。。不过还是要谢谢!