我用代码生成了一个按钮,运行时每单击一次,调用单击方法的次数在某个范围内递增,而不是只调用一次(这不是我想要的),请问这是什么地方出错了呢,请有相关经验的朋友帮我分析一下各种可能性:)

解决方案 »

  1.   

    应该是按钮的单击事件注册的问题,就是.click += ....的问题
      

  2.   

    在这个注册方面,有可能出什么问题呢,
       this.delRow.Click += new EventHandler(this.click_DelRow1);
    delRow是按钮,click_DelRow1是单击事件.
      

  3.   

    生成按钮的代码:
         this.delRow.Location = new System.Drawing.Point(3, 15 + partitionRow * 27);
                        this.delRow.TabIndex = partitionRow * 2 ;
                        this.delRow.Text = "删除本条纪录";
                        this.delRow.BackColor = SystemColors.Control;
                        this.delRow.UseVisualStyleBackColor = true;
                        this.delRow.AutoSize = true;
                        this.delRow.Click += new EventHandler(this.click_DelRow1);
                        panel2.Controls.Add( this.delRow);
    单击事件:
         private void click_DelRow1(object sender, EventArgs e)
            {
                string[] idInfo=new string[2];
                idInfo[0] = this.showKey[0].Text;
                idInfo[1] = this.showValue[0].Text;
                Hashtable idDel = new Hashtable();
                idDel.Add(0,idInfo);
                Boolean delResult = this.test.ExecuteDelete(this.xmlName,idDel);
                if (delResult)
                    MessageBox.Show("succeed to delete!");
                else
                    MessageBox.Show("fail to delete :(");
            }
      

  4.   

    this.delRow.Click += new EventHandler(this.click_DelRow1);
    这条语句做个断点看看,不会是这个执行了多次吧。Web的程序?