c#为什么点击网页的刷新按钮后会执行button按钮事件里的内容啊?
我在页面添加了<asp:Button ID="btn_huitie" runat="server" onclick="btn_huitie_Click" Text="回 帖" />按钮,点击之后添加成功,然后再点刷新按钮(F5),为什么会执行回帖按钮里面的内容啊?谢谢大家帮我啊

解决方案 »

  1.   

    楼主,为什么不发到C#版,我帮你转过去吧。
    本版是讨论VC的。
      

  2.   

    wenxy1我是该把帖子结了,把分给你吗?
      

  3.   

    如果一个页面表单,在提交后,如果再刷新此页,将根据viewstate回传执行按钮事件重复提交. 
    可用IsPostBack
      

  4.   

    就是最下面的那个按扭
    namespace dtt.Web
    {
        public partial class detilTie2 : System.Web.UI.Page
        {
            int tid = 0;
            protected void Page_Load(object sender, EventArgs e)
            {
                string tids = Request.Params["tid"];
                tid = Convert.ToInt32(tids);
                this.dq_uname.Text = Session["uname"].ToString();
                this.dq_uid.Text = Session["uid"].ToString();
                if (!IsPostBack)
                {
                    query();
                    showHuiTie();
                }
            }
            public void query()
            {
                if (tid != 0)
                {
                    dtt.BLL.faTie bll = new dtt.BLL.faTie();
                    DataSet ds = bll.GetList("tid=" + tid);
                    this.tid1.Text = tid.ToString();
                    this.TextArea1.Value = ds.Tables[0].Rows[0][1].ToString();
                    this.uname.Text = ds.Tables[0].Rows[0][2].ToString();            }        }
            public void showHuiTie()
            {
                dtt.BLL.huiTie bll = new dtt.BLL.huiTie();
                DataSet ds = bll.GetList(0,"tid=" + tid + "and rrid="+0,"rid desc");
              
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    sb.Append("<table id='tabl_"+i+"' border='1'><tr><th>回帖id</th><th>回帖人id</th><th>原帖子id</th><th>rrid</th></tr>");
                    sb.Append("<tr><td>'" + ds.Tables[0].Rows[i][0] + "'</td><td>'" + ds.Tables[0].Rows[i][1] + "'</td><td>'" + ds.Tables[0].Rows[i][2] + "'</td><td>'" + ds.Tables[0].Rows[i][4] + "'</td></tr>");
                    sb.Append("<tr width='40' height='100'><td colspan='4'><input id='dw_" + ds.Tables[0].Rows[i][0] + "' type='text' disabled='disabled' value='" + ds.Tables[0].Rows[i][3].ToString() + "' style='height: 149px; width: 750px' /></td></tr>");
                   // sb.Append("<tr><td colspan='4'><input id='rr_" + ds.Tables[0].Rows[i][0] + "' type='button' value='回帖' onclick='return Button2_onclick(rid=" + ds.Tables[0].Rows[i][0] + ")' /></td></tr>");
                    sb.Append("</table>");                DataSet ds2 = bll.GetList("tid=" + tid + "and rrid=" + ds.Tables[0].Rows[i][0]);
                    if (ds2 != null)
                    { 
                        for (int j = 0; j < ds2.Tables[0].Rows.Count; j++)
                        { 
                            sb.Append("<table id='tabl2_" + j + "' border='1'><tr><th>rid</th><th>回帖人id</th><th>原帖子id</th><th>针对哪个回复来回复的</th></tr>");
                            sb.Append("<tr><td>'" + ds2.Tables[0].Rows[j][0] + "'</td><td>'" + ds2.Tables[0].Rows[j][1] + "'</td><td>'" + ds2.Tables[0].Rows[j][2] + "'</td><td>'" + ds2.Tables[0].Rows[j][4] + "'</td></tr>");
                            sb.Append("<tr width='40' height='100'><td colspan='4'><input id='dw2_" + ds2.Tables[0].Rows[j][0] + "' type='text' disabled='disabled' value='" + ds2.Tables[0].Rows[j][3].ToString() + "' style='height: 149px; width: 750px' /></td></tr>");
                           // sb.Append("<tr><td colspan='4'><input id='rr_" + ds2.Tables[0].Rows[i][0] + "' type='button' value='回帖' onclick='return Button2_onclick(rid=" + ds2.Tables[0].Rows[i][0] + ")' /></td></tr>");
                            //sb.Append("</table>");
                        }
                    }
                    sb.Append("<tr><td colspan='4'><input id='rr_" + ds.Tables[0].Rows[i][0] + "' type='button' value='回帖' onclick='return Button2_onclick(rid=" + ds.Tables[0].Rows[i][0] + ")' /></td></tr>");
                    sb.Append("</table><hr/><br/><br/>");
                     
                }
                PlaceHolder1.Controls.Add(new LiteralControl(sb.ToString()));
            }        protected void btn_huitie_Click(object sender, EventArgs e)
            {
                dtt.Model.huiTie model = new dtt.Model.huiTie();
                model.uid = Convert.ToInt32(Session["uid"]);
                model.tid = tid;
                model.r_reirong = txt_huitie.Text;
                model.rrid = 0;
                dtt.BLL.huiTie bll = new dtt.BLL.huiTie();
                int i = bll.Add(model);
                if (i > 0)
                {
                    Response.Write("回帖成功。");
                    txt_huitie.Text = "";
                    showHuiTie();
                }
                else
                {
                    Response.Write("回帖失败。");
                }
            }
        }
    }
      

  5.   

    这怎么改呢?
    namespace dtt.Web 

        public partial class detilTie2 : System.Web.UI.Page 
        { 
            int tid = 0; 
            protected void Page_Load(object sender, EventArgs e) 
            { 
                string tids = Request.Params["tid"]; 
                tid = Convert.ToInt32(tids); 
                this.dq_uname.Text = Session["uname"].ToString(); 
                this.dq_uid.Text = Session["uid"].ToString(); 
                if (!IsPostBack) 
                { 
                    query(); 
                    showHuiTie(); 
                } 
            } 
            public void query() 
            { 
                if (tid != 0) 
                { 
                   //
                }         } 
            public void showHuiTie() 
            { 
                  // 
            }         protected void btn_huitie_Click(object sender, EventArgs e) 
            { 
                dtt.Model.huiTie model = new dtt.Model.huiTie(); 
                model.uid = Convert.ToInt32(Session["uid"]); 
                model.tid = tid; 
                model.r_reirong = txt_huitie.Text; 
                model.rrid = 0; 
                dtt.BLL.huiTie bll = new dtt.BLL.huiTie(); 
                int i = bll.Add(model); 
                if (i > 0) 
                { 
                    Response.Write("回帖成功。"); 
                    txt_huitie.Text = ""; 
                    showHuiTie(); 
                } 
                else 
                { 
                    Response.Write("回帖失败。"); 
                } 
            } 
        }