ispostback问题

chenghj87 2009-05-06 04:40:24
我原来是xp系统,vs2008+sql2005 做了一个博客系统在pageload用ispostback来绑定数据库,运行完全没问题
但是后来换了vista,也是vs2008+sql2005,但是运行之前的博客时,点击页面按钮式(例如删除评论等)似乎不会跳到ispostback里面的那个绑定的方法。

这是一个删除评论的代码,现在删除评论之后不会重新加载了,本来xp下面可以的。。
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Admin_Default : System.Web.UI.Page
{
private string sConnectionString = ConfigurationManager.ConnectionStrings["blogConnString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{

if (!IsCallback )
{
Bind();
}


}

private void Bind()
{
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(sConnectionString))
{
SqlDataAdapter da = new SqlDataAdapter("select * from wenzhang;select * from comment", conn);
da.Fill(ds);
}
ds.Relations.Add("relationsbetweenwenzhangandcomment", ds.Tables[0].Columns["blog_id"], ds.Tables[1].Columns["commentblog_id"]);
Repeater3.DataSource = ds;
Repeater3.DataBind();
}

protected void Repeater4_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "delcomment")
{
using (SqlConnection conn = new SqlConnection(sConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("delete from comment where comment_id=@commentid", conn))
{
cmd.Parameters.AddWithValue("@commentid", e.CommandArgument);
cmd.ExecuteNonQuery();

}
}
}
}
}
...全文
119 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
net_xiaojian 2009-05-06
  • 打赏
  • 举报
回复
根本就不是在一个repeater里面做一件事吧?!
net_xiaojian 2009-05-06
  • 打赏
  • 举报
回复
呵呵,你绑定的是Repeater3,怎么在Repeater4里面的ItemCommand,取名真牛。
wodexiaohao 2009-05-06
  • 打赏
  • 举报
回复
打个断点,f11逐步调试看看,因为没数据库,大家没办法帮你做这一步
chenghj87 2009-05-06
  • 打赏
  • 举报
回复
13楼的方法和事件之后在运行下bind方法差不多啊,但是我就是搞不懂原来xp上可以,为什么到了vista上就不行了,是.net版本问题?
protected void Repeater4_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "delcomment")
{
using (SqlConnection conn = new SqlConnection(sConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("delete from comment where comment_id=@commentid", conn))
{
cmd.Parameters.AddWithValue("@commentid", e.CommandArgument);
cmd.ExecuteNonQuery();
Bind();
}
}
}
}
net_xiaojian 2009-05-06
  • 打赏
  • 举报
回复

public partial class Admin_Default : System.Web.UI.Page
{
private bool mbRebind = false;
private string sConnectionString = ConfigurationManager.ConnectionStrings["blogConnString"].ToString();
protected void Page_PreRender(object sender, EventArgs e)
{

if (!IsCallback || mbRebind)
{
Bind();
}


}

private void Bind()
{
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(sConnectionString))
{
SqlDataAdapter da = new SqlDataAdapter("select * from wenzhang;select * from comment", conn);
da.Fill(ds);
}
ds.Relations.Add("relationsbetweenwenzhangandcomment", ds.Tables[0].Columns["blog_id"], ds.Tables[1].Columns["commentblog_id"]);
Repeater3.DataSource = ds;
Repeater3.DataBind();
}

protected void Repeater4_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "delcomment")
{
using (SqlConnection conn = new SqlConnection(sConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("delete from comment where comment_id=@commentid", conn))
{
cmd.Parameters.AddWithValue("@commentid", e.CommandArgument);
cmd.ExecuteNonQuery();
mbRebind = true;
}
}
}
}
}



这样准行,不行掐它...
dengyun_1223 2009-05-06
  • 打赏
  • 举报
回复
关注
wodexiaohao 2009-05-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 shove 的回复:]
if (!IsCallback )
{
Bind();
}


这里写错了


!IsPostBack
[/Quote]

正解,楼主说的是Postback,这里疑似误写成了Callback
如果是误解,请你再详细的阐明一下这个问题,我们大家会乐于帮助的
shuijing116 2009-05-06
  • 打赏
  • 举报
回复
if (!IsPostback )
llsen 2009-05-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 chenghj87 的回复:]
我发错了,。。原来应该是ispostback的,但是也不行
[/Quote]

还怎么不行那
gyouyang 2009-05-06
  • 打赏
  • 举报
回复
删除后在调用一下绑定方法,这样看行不行
[code=C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Admin_Default : System.Web.UI.Page
{
private string sConnectionString = ConfigurationManager.ConnectionStrings["blogConnString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{

if (!IsCallback )
{
Bind();
}


}

private void Bind()
{
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(sConnectionString))
{
SqlDataAdapter da = new SqlDataAdapter("select * from wenzhang;select * from comment", conn);
da.Fill(ds);
}
ds.Relations.Add("relationsbetweenwenzhangandcomment", ds.Tables[0].Columns["blog_id"], ds.Tables[1].Columns["commentblog_id"]);
Repeater3.DataSource = ds;
Repeater3.DataBind();
}

protected void Repeater4_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "delcomment")
{
using (SqlConnection conn = new SqlConnection(sConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("delete from comment where comment_id=@commentid", conn))
{
cmd.Parameters.AddWithValue("@commentid", e.CommandArgument);
cmd.ExecuteNonQuery();

}
this.Bind();
}
}
}
}

][/code]
chenghj87 2009-05-06
  • 打赏
  • 举报
回复
我发错了,。。原来应该是ispostback的,但是也不行
gyouyang 2009-05-06
  • 打赏
  • 举报
回复
汗啊

if (!IsCallback )
{
Bind();
}


if (!IsPostBack)
{
Bind();
}


你看看是那个吧....昏厥
douzexin1111 2009-05-06
  • 打赏
  • 举报
回复
为什么要用IsCallback 呢??应该是IsPostBack吧?
周公 2009-05-06
  • 打赏
  • 举报
回复
 { 

if (!IsPostback )// 是!IsPostback 而不是!IsCallback
{
Bind();
}


}

chenghj87 2009-05-06
  • 打赏
  • 举报
回复
怎么跟踪啊?
dsr456 2009-05-06
  • 打赏
  • 举报
回复
有没有跟踪过,应该不会有这种问题吧
shove 2009-05-06
  • 打赏
  • 举报
回复
if (!IsCallback )
{
Bind();
}



这里写错了


!IsPostBack

62,267

社区成员

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

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

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

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