如何在Page_Load里用JS实现页面跳转

movytop 2009-12-28 02:12:26
目标:实现页面加载的时候弹出提示框,点击确定后跳转到指定页面。

我的方法:
一个空白的页面。
C#后台如下代码:

protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<script type=\"text/javascript\">alert(\"fdfdf\");location(\"default.aspx\")</script>");
}


存在问题:
alert事件可以实现,但是无法实现location事件。

请高手赐教!
...全文
192 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
angel6709 2009-12-28
  • 打赏
  • 举报
回复
muji
  • 打赏
  • 举报
回复
顶了。。。。。。。。。
goldxinx 2009-12-28
  • 打赏
  • 举报
回复

protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('Hello!');window.location.replace('Default.aspx')</script>");
}

kings2015 2009-12-28
  • 打赏
  • 举报
回复

ClientScript.RegisterStartupScript(this.GetType(),"redirect","alert('跳转');location.href='default.aspx';",true);
wclhack 2009-12-28
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<script>alert('Hello');window.open("Default.aspx");</script>");
}
chengcheng1253 2009-12-28
  • 打赏
  • 举报
回复
可以在body 里面onload 里面写也一样啊
amandag 2009-12-28
  • 打赏
  • 举报
回复
  protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<script type='text/javascript'>alert('fdfdf');location.href=('default.aspx');</script>");
}


movytop 2009-12-28
  • 打赏
  • 举报
回复
楼上正解啊。谢谢。

想问下,location于location.href有什么区别呢。

如果以上代码写在button_click里为什么能正常运行呢。

楼下解答吧。
threenewbee 2009-12-28
  • 打赏
  • 举报
回复
你在客户端浏览器查看源代码就知道怎么回事了。
lhz_dxm 2009-12-28
  • 打赏
  • 举报
回复
Response.Write("<script type=\"text/javascript\">alert(\"fdfdf\");</script>");
Response.Write("<script>window.location.href="\default.aspx\" </script>");
阿非 2009-12-28
  • 打赏
  • 举报
回复
location.href='default.aspx';

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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