Asp.net弹出框并跳转到另一个页面

Momolt 2014-10-09 04:07:45
/// <summary>
/// 弹出JavaScript小窗口,并转向指定的页面
/// </summary>
/// <param name="message">弹出信息</param>
/// <param name="toURL">跳转到的网页</param>
public static void AlertAndRedirect(string message, string toURL)
{
string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
HttpContext.Current.Response.Write(string.Format(js, message, toURL));
}

public static void GoRedirect(string toURL)
{
string js = "<script language=javascript>window.location.replace('{0}')</script>";
HttpContext.Current.Response.Write(string.Format(js, toURL));
}

public static void ToRedirect(string toURL)
{
string js = "<script language=javascript>parent.location.replace('{0}')</script>";
HttpContext.Current.Response.Write(string.Format(js, toURL));
}

public static void AlertAndRedirectParent(string message, string toURL)
{
string js = "<script language=javascript>alert('{0}');parent.location.replace('{1}')</script>";
HttpContext.Current.Response.Write(string.Format(js, message, toURL));
}
...全文
268 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhj_2679464683 2014-10-10
  • 打赏
  • 举报
回复
Asp.net javascript弹出框跳转页面示例 Response.Write("<script lanuage=javascript>alert('验证码错误');location='javascript:history.go(-1)'</script>");//弹出对话框返回到原来页面 Response.Write("<script language=javascript>alert('文章添加成功!');location='ArticleManage.aspx'</script>");//关闭对话框跳转到设置页面 Response.Write("<script language=javascript>alert('对不起!请先注册再登录!');location='../../GuangIndex.aspx'</script>");//跳转到上级页面
myhope88 2014-10-10
  • 打赏
  • 举报
回复
最好用this.ClientScript.RegisterStartupScript这个来操作
fuyifang 2014-10-09
  • 打赏
  • 举报
回复
推荐使用 this.ClientScript.RegisterStartupScript,比HttpContext.Current.Response.Write好使
暖枫无敌 2014-10-09
  • 打赏
  • 举报
回复
是分享吧,赞一个!
mc_dv 2014-10-09
  • 打赏
  • 举报
回复
用JS嘛, 多方便 .
  • 打赏
  • 举报
回复
引用 2 楼 diaodiaop 的回复:

    /// <summary>
    /// 弹出对话框
  /// </summary>
    /// <param name="page">Page或者this</param>
    /// <param name="str">值 如'登陆成功!'</param>
    public static void show(Page page, string str)
    {
        page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script language='javascript'>alert('" + str + "');</script>");
    }

/// <summary>
    /// 弹出对话框 并且跳转界面
    /// </summary>
    /// <param name="page">Page或者this</param>
    /// <param name="str">值 如'登陆成功!'</param>
    /// <param name="url">要跳转的界面 如'admin/main.aspx'</param>
    public static void show(Page page, string str, string url)
    {
        page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script language=javascript>alert('" + str + "');location.href='" + url + "';</script>");
        
    }
表示只用过这个。
by_封爱 2014-10-09
  • 打赏
  • 举报
回复
怎么还用Write......
by_封爱 2014-10-09
  • 打赏
  • 举报
回复

    /// <summary>
    /// 弹出对话框
  /// </summary>
    /// <param name="page">Page或者this</param>
    /// <param name="str">值 如'登陆成功!'</param>
    public static void show(Page page, string str)
    {
        page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script language='javascript'>alert('" + str + "');</script>");
    }

/// <summary>
    /// 弹出对话框 并且跳转界面
    /// </summary>
    /// <param name="page">Page或者this</param>
    /// <param name="str">值 如'登陆成功!'</param>
    /// <param name="url">要跳转的界面 如'admin/main.aspx'</param>
    public static void show(Page page, string str, string url)
    {
        page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script language=javascript>alert('" + str + "');location.href='" + url + "';</script>");
        
    }
我本良人 2014-10-09
  • 打赏
  • 举报
回复

62,047

社区成员

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

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

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

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