自动弹出窗口问题

zhuwei1987 2008-03-22 10:17:17
protected void Button1_Click1(object sender, EventArgs e)
{
string Title = txtTitle.Text;
string Content = this.WebEditor1.Text;

Model model = new Model();
model.Title=Title;
model.Content=Content;

try
{
CatalogDataBase.AddArticle(model);
MessageBox.Show(this, "添加文章成功!");
Response.Redirect("Article_Add.aspx");
}
catch
{
MessageBox.Show(this, "添加文章失败!");
}

}

以下是MessageBox类的代码
public class MessageBox
{
public static void Show(System.Web.UI.Page page, string msg)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
}
}

为什么添加失败就能弹出窗口.
而添加成功了却不能弹出添加成功窗口..
...全文
202 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qfgyd2004 2008-03-22
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhoufoxcn 的回复:]
Response.write(" <script>alert('添加文章成功');window.location='Article_Add.aspx'; </script>");
这句正解!

MessageBox.Show(this, "添加文章成功!");
Response.Redirect("Article_Add.aspx");
这种方式有两个问题:
一、使用的MessageBox类是WinForm的,不好,要使用web的方式,就是alert方式;
二、在弹出提示框之后,页面马上就跳转了,所以看不见提示信息。
[/Quote]
lucky749 2008-03-22
  • 打赏
  • 举报
回复
try
{
CatalogDataBase.AddArticle(model);
MessageBox.Show..去掉
换 Response.write("<script>alert('添加文章成功');window.location='Article_Add.aspx'; </script>");

Response.Redirect("Article_Add.aspx");
}
catch
{
MessageBox.Show(this, "添加文章失败!");
}
江门拓胜科技 2008-03-22
  • 打赏
  • 举报
回复
Response.Redirect("Article_Add.aspx");
很正常啊,应该不会错,

LZ检查过CatalogDataBase.AddArticle(model); 没有?
错误应该在这里冒出来的吧,
beautifuldays 2008-03-22
  • 打赏
  • 举报
回复
你把 Response.Redirect("Article_Add.aspx");
改写成 Server.Transfer("Article_Add.aspx");
试一试
周公 2008-03-22
  • 打赏
  • 举报
回复
Response.write(" <script>alert('添加文章成功');window.location='Article_Add.aspx'; </script>");
这句正解!

MessageBox.Show(this, "添加文章成功!");
Response.Redirect("Article_Add.aspx");
这种方式有两个问题:
一、使用的MessageBox类是WinForm的,不好,要使用web的方式,就是alert方式;
二、在弹出提示框之后,页面马上就跳转了,所以看不见提示信息。
scjtswj 2008-03-22
  • 打赏
  • 举报
回复
Response.write(" <script>alert('添加文章成功');window.location='Article_Add.aspx'; </script>");
yb1124 2008-03-22
  • 打赏
  • 举报
回复
试着把 Response.Redirect("Article_Add.aspx"); 去掉
换成Response.write("<script>window.open('Article_Add.aspx')</script>");试试
yb1124 2008-03-22
  • 打赏
  • 举报
回复
因为有 Response.Redirect("Article_Add.aspx");
所以直接执行Response.Redirect了

62,254

社区成员

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

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

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

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