asp.net中的alert

meceky 2009-03-21 03:44:25
在asp.net页面中怎么处理那个
response.write("<script language=javascript>alert('登录失败');</script>");
Response.write("index.aspx");
实际上总是直接跳转到index.aspx,
怎么样才能实现那只种效果啊。在alert以后再实现页面的跳转
...全文
156 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
toxxj 2009-03-22
  • 打赏
  • 举报
回复
这里写了个封装的类,你可以下载去看下

一个封装的在后台弹出JS Alert消息和JS confirm信息以及跳转到指定的页面
http://www.cnblogs.com/xiaoxijin/archive/2008/03/23/1118172.html


/// <summary>

/// javascript彈出消息後,跳轉到指定的URL鏈接頁面

/// </summary>

/// <param name="message">要彈出的消息內容</param>

/// <param name="pageUrl">要跳轉到的頁面鏈接,站內鏈接請填寫相對路徑,站外的鏈接需要加上"http://",如"http://www.baidu.com"</param>

/// <param name="page">當前頁面,參數可以直接寫:this 或 Page</param>

public static void AlertAndGotoUrl(string message, string pageUrl, Page page)

{

string strScript = "alert('" + message + "');window.location.href='" + pageUrl + "';";

page.ClientScript.RegisterStartupScript(page.GetType(), null, strScript, true);

}

delphi_new 2009-03-22
  • 打赏
  • 举报
回复
服务器总是优于客户端执行,你这样肯定是先之下重定向咯,
Response.Write(" <script>alert('登录失败');window.location.href='index.aspx'; </script>");
wuyq11 2009-03-22
  • 打赏
  • 举报
回复
public static void ShowMsg(string msg, string toURL)
{
string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
HttpContext.Current.Response.Write(string.Format(js, msg, toURL));
HttpContext.Current.Response.End();
}
houndsky 2009-03-22
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 houndsky 的回复:]
你直接调用下这个就可以了!

C# code
/// <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…
[/Quote]

.net中一些常用的JS方法:http://www.li-gang.cn/200903/25.html
houndsky 2009-03-22
  • 打赏
  • 举报
回复
你直接调用下这个就可以了!

/// <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));
}
erytbc 2009-03-21
  • 打赏
  • 举报
回复
Response.Write("<script>alert('登录失败');window.location.href='index.aspx';</script>");
Riverwcj 2009-03-21
  • 打赏
  • 举报
回复
response.write(" <script language=javascript>alert('登录失败');window.location.href='index.aspx'; </script>");
xsm545 2009-03-21
  • 打赏
  • 举报
回复
楼上正解
liucfy 2009-03-21
  • 打赏
  • 举报
回复
其实在这种情况下用Respose.Write(Script);也可以。如果不是页面跳转的话不建议用Response.Write().因为它破口Html的结构
liucfy 2009-03-21
  • 打赏
  • 举报
回复
最好的解决办法:

string Script="alert('OK!');window.location='index.aspx';";
ClientScript.RegisterClientScriptBlock(this.GetType(),Script,true);
嘴哥臭鼬 2009-03-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 shangxb 的回复:]
C# codeResponse.Write("<script>alert('登录失败');window.location.href='index.aspx';</script>");
[/Quote]似的
HsWong 2009-03-21
  • 打赏
  • 举报
回复
用Ajax
chouto 2009-03-21
  • 打赏
  • 举报
回复
response.write(" <script language=javascript>alert('登录失败'); window.location.href='index.aspx';</script>");
shangxb 2009-03-21
  • 打赏
  • 举报
回复
Response.Write("<script>alert('登录失败');window.location.href='index.aspx';</script>");
wenrenhehe 2009-03-21
  • 打赏
  • 举报
回复
用confirm

62,268

社区成员

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

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

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

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