帮忙看看为啥不执行呢?

bshedu2 2011-10-14 03:11:16


protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
{
atrilID = Convert.ToInt32(Request.QueryString["id"]);//得到文章id
article = bllArticle.GetModel(atrilID);
if (article==null) //输入的id不存在。
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert(' 错误文章ID,面页即将关闭!');this.close()", true);

}
else
{
asArticle();
}

}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert(' 错误文章ID,面页即将关闭!');this.close()", true);

}
}


最下面的 警告窗口可以执行,但是为啥中间的警告就是不出来~~
...全文
91 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
bshedu2 2011-10-16
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 shenyong985873401 的回复:]

不是写的挺明白的吗Request.QueryString["id"]等于NULL呗
[/Quote]

不是的。。有这个值。。看我的一楼原帖。我现在要做的判断是 1 ,传来的id为空,也就是直接开的xxx.aspx 而不是xxx.aspx?id=123 如果传来的id为空 就报错。2,传来的id不为空,但是这个id在数据库中没有,比如我最大的id是123,他非要输入xxx.aspx?id=124 这个124显然查不到文章,所以也要报错告诉他这个id是错的,但就是弹不出错哎。。。。 article = bllArticle.GetModel(atrilID); //根据id去查文章,返回值是文章实例
if (article==null) //输入的id不存在,返回的实例为空。

我切断点。。这个article==null是成立的。。里面的语句也执行了,但是就是看不到执行应该弹出的框框
沈勇 2011-10-16
  • 打赏
  • 举报
回复
不是写的挺明白的吗Request.QueryString["id"]等于NULL呗
bshedu2 2011-10-16
  • 打赏
  • 举报
回复
up~~
acol 2011-10-14
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 bshedu2 的回复:]

引用 9 楼 csy19871106 的回复:

C# code

public int id
{
get
{
if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.QueryString["id"]))
{
return int.Parse(Sy……



依然不执行。。。
articl……
[/Quote]
你断点调试下。 看下ID取到了没。
successful_cdr 2011-10-14
  • 打赏
  • 举报
回复
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert(' 错误文章ID,面页即将关闭!');this.close();", true);

this.close()后面加上;
accpwangxinchao 2011-10-14
  • 打赏
  • 举报
回复
感觉是你弹出的那块写错了
bshedu2 2011-10-14
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 csy19871106 的回复:]

C# code

public int id
{
get
{
if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.QueryString["id"]))
{
return int.Parse(Sy……
[/Quote]


依然不执行。。。
article = bllArticle.GetModel(atrilID);
if (article==null) //输入的id不存在。
{
这里的article是根据id查询到的文章实体。。
我想做的判断是,但输入了id但这个id不在数据库中,查到的article 不存在,就就弹出警告,我切断点发现,确实是null里面的话也确实执行了,但是没看到窗口。。这就郁闷了。。
1800包吃包住 2011-10-14
  • 打赏
  • 举报
回复

article它不等于NULL 怎么执行啊!!!
if(article==null)
acol 2011-10-14
  • 打赏
  • 举报
回复

public int id
{
get
{
if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.QueryString["id"]))
{
return int.Parse(System.Web.HttpContext.Current.Request.QueryString["id"].ToString());
}
else
{
return 0;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
if (id>0)
{
atrilID = Convert.ToInt32(Request.QueryString["id"]);//得到文章id
article = bllArticle.GetModel(atrilID);
if (article==null) //输入的id不存在。
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert(' 错误文章ID,面页即将关闭!');this.close()", true);

}
else
{
asArticle();
}

}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert(' 错误文章ID,面页即将关闭!');this.close()", true);

}
}
}

这样应该没事了
zhouzhenhuaqaz 2011-10-14
  • 打赏
  • 举报
回复
if(IsPostBack)
{

}
加上这个
ChinaXtHuLang 2011-10-14
  • 打赏
  • 举报
回复
少了:if (IsPostBack)
的判断。
  • 打赏
  • 举报
回复
article类型是神马
acol 2011-10-14
  • 打赏
  • 举报
回复
这应该是你的id不是null.

public int id
{
get
{
if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.QueryString["id"]))
{
return int.Parse(System.Web.HttpContext.Current.Request.QueryString["id"].ToString());
}
else
{
return 0;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (id>0)
{
atrilID = Convert.ToInt32(Request.QueryString["id"]);//得到文章id
article = bllArticle.GetModel(atrilID);
if (article==null) //输入的id不存在。
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert(' 错误文章ID,面页即将关闭!');this.close()", true);

}
else
{
asArticle();
}

}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert(' 错误文章ID,面页即将关闭!');this.close()", true);

}
}

w290601645 2011-10-14
  • 打赏
  • 举报
回复

protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
return;//加上这个

if (Request.QueryString["id"] != null)
{
atrilID = Convert.ToInt32(Request.QueryString["id"]);//得到文章id
article = bllArticle.GetModel(atrilID);
if (article==null) //输入的id不存在。
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert(' 错误文章ID,面页即将关闭!');this.close()", true);

}
else
{
asArticle();
}

}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert(' 错误文章ID,面页即将关闭!');this.close()", true);

}
}


cqfeng 2011-10-14
  • 打赏
  • 举报
回复
那就是if (article==null) 这个条件不满足呗
laowang134 2011-10-14
  • 打赏
  • 举报
回复
Request.QueryString["id"]在数据库是存在的吧。。
橙宝宝 2011-10-14
  • 打赏
  • 举报
回复
这不是写的挺明白的吗Request.QueryString["id"]等于NULL呗

62,050

社区成员

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

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

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

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