我原来是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 (!IsPostBack ) 
        { 
            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(); 
                    
                } 
            } 
        } 
    } 

解决方案 »

  1.   

    if (!IsPostBack ) 
    这里去掉就可以了。
      

  2.   

    不能删除 if (!IsPostBack ) 
    BS每个服务器动作都会先进入PageLoad
    所以每回都重新绑定一遍 ,
      

  3.   

    删除事件那里调用,那用ispostback就没什么用了啊。
    现在就是按删除的话,不会重新绑定数据库
      

  4.   

    重新点击这个页面就可以的,但是就是点删除按钮之后不会重新绑定,是不是系统问题啊,xp上做的时候完全可以,到了vista上就不行了
      

  5.   


    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 (!IsPostBack || 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;
                    } 
                } 
            } 
        } 
    } 好像你发了俩个贴,那贴里面吧IsCallBack改成IsPostBack.
      

  6.   

       在删除方法里面的最后用   Response.Redirect("删除页面");  
      

  7.   

    Page.IsPostBack 属性
    获取一个值,该值指示该页是否正为响应客户端回发而加载,或者它是否正被首次加载和访问。 
    如果是为响应客户端回发而加载该页,则为 true;否则为 false。 
    具体的楼主可以参考MSDN.
      

  8.   

    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();
                        
                    } 
                } 
            } 
        }