奇怪的现象!!!!

longling520 2009-01-03 01:13:58
今天我做了一个页面传值的网页,如下
Default.aspx页面:

当按下前四个按钮时会报错:无法将类型为“ASP.receive__aspx”的对象强制转换为类型“_Default”。
只按第五个按钮时不会报错,或者注释掉第五按钮的内容,再按前面四个按钮也不会报错,不知道为什么?希望各位帮我看看,谢谢!

Default.aspx代码:

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)
{
// Value sent using HttpResponse
Response.Redirect("receive .aspx?Name=" + txtName.Text);

}

protected void Button2_Click(object sender, EventArgs e)
{
HttpCookie cName = new HttpCookie("Name");
cName.Value = txtName.Text;
Response.Cookies.Add(cName);
Response.Redirect("receive .aspx");
}

protected void Button3_Click(object sender, EventArgs e)
{
Session["Name"] = txtName.Text;
Response.Redirect("receive .aspx");
}

protected void Button4_Click(object sender, EventArgs e)
{
Application["Name"] = txtName.Text;
Response.Redirect("receive .aspx");
}
protected void Button5_Click(object sender, EventArgs e)
{

Server.Transfer("receive .aspx");
}

public string GetName
{
get
{
return txtName.Text;
}
}

}





receive.aspx页面代码:

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 receive_ : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["Name"] != null)
Label1.Text = Request.QueryString["Name"];

if (Request.Cookies["Name"] != null)
Label4.Text = Request.Cookies["Name"].Value;

// The code below shows how to get the session value.
// This code must be placed in other page.
if (Session["Name"] != null)
Label6.Text = Session["Name"].ToString();

if (Application["Name"] != null)
Label8.Text = Application["Name"].ToString();

// You can declare this Globally or in any event you like
_Default w;
// Gets the Page.Context which is Associated with this page
w = (_Default)Context.Handler;
// Assign the Label control with the property "GetName" which returns string
Label10.Text = w.GetName;

}
}

...全文
88 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
海倍娜楽 2009-01-03
  • 打赏
  • 举报
回复
楼主传参,对参数进行一下URL编码...
wndsc 2009-01-03
  • 打赏
  • 举报
回复
lu guo
我姓区不姓区 2009-01-03
  • 打赏
  • 举报
回复

protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["Name"] != null)
Label1.Text = Request.QueryString["Name"];

else if (Request.Cookies["Name"] != null)
Label4.Text = Request.Cookies["Name"].Value;

// The code below shows how to get the session value.
// This code must be placed in other page.
else if (Session["Name"] != null)
Label6.Text = Session["Name"].ToString();

else if (Application["Name"] != null)
Label8.Text = Application["Name"].ToString();

else if(Context.Handler is _Default)
{
// You can declare this Globally or in any event you like
_Default w;
// Gets the Page.Context which is Associated with this page
w = (_Default)Context.Handler;
// Assign the Label control with the property "GetName" which returns string
Label10.Text = w.GetName;
}
}

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧