我在MultiPage的PageView中加了一个Button,在page_load中加入this.btnSave.Click += new System.EventHandler(this.btnSave_Click);点击按钮没有任何反应,我在btnSave_Click设了断点,发现根本不到那,这是怎么回事呢

解决方案 »

  1.   

    好像不应该加在page_load中吧,应该加在InitializeComponent中。
      

  2.   

    不是在Page_load中,是在InitializeComponent中写
      

  3.   

    在InitializeComponent中写还是没有反应,我设了断点,还是不跳到那,怎么办呢?
      

  4.   

    在这里写 OnInit(EventArgs e)
    在这写InitializeComponent事件会丢失
      

  5.   

    在InitializeComponent()中按钮事件丢失了。
      

  6.   

    smallMage(小马哥) :
    OnInit(EventArgs e)函数怎么没有看到呢这是单击事件,程序不会执行到这里
    private void btnSave_Click(object sender, System.EventArgs e)
    {
    int re=ber.AddUser(txtName.Text.Trim().ToString(),txtPassword.Text.Trim().ToString(),int.Parse(drpDept.SelectedValue.ToString()),
    int.Parse(drpRank.SelectedValue.ToString()),int.Parse(drpRight.SelectedValue.ToString()));
    if( re!=-1)
    {
    ShowMsg("保存成功!");
    }
    else
    {
    ShowMsg("保存失败,记录已存在!");
    }
    }
      

  7.   

    这是整个页面的代码,我把它放在OnInit(EventArgs e)中了,还是没有反应呢?using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using BLL;
    namespace Web
    {
    /// <summary>
    /// Staff 的摘要说明。
    /// </summary>
    public class Staff : System.Web.UI.Page
    {
    protected Microsoft.Web.UI.WebControls.TabStrip TabStrip1;
    protected Microsoft.Web.UI.WebControls.MultiPage MultiPage1;
    protected DropDownList drpDept,drpRank,drpRight;
    protected TextBox txtName,txtPassword;
    protected Button btnSave=new Button();
    private User ber=new User();
    private void Page_Load(object sender, System.EventArgs e)
    {

    if (!IsPostBack)
    {
    FillRight();
    FillDept();
    FillRank();
    }

    }

    private void FillDept()
    {
    SqlDataReader dr=ber.AllDept();
    drpDept.DataSource=dr;
    drpDept.DataTextField="DeptDesc";
    drpDept.DataValueField="DeptID";
    drpDept.DataBind();
    } private void FillRank()
    {
    drpRank.DataSource=ber.AllRank();
    drpRank.DataTextField="RankDesc";
    drpRank.DataValueField="RankID";
    drpRank.DataBind();
    } private void FillRight()
    {
    drpRight.DataSource=ber.AllRight();
    drpRight.DataTextField="GroupDesc";
    drpRight.DataValueField="GroupID";
    drpRight.DataBind();
    }

    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
    InitializeComponent();

    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {     this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void btnSave_Click(object sender, System.EventArgs e)
    {
    int re=ber.AddUser(txtName.Text.Trim().ToString(),txtPassword.Text.Trim().ToString(),int.Parse(drpDept.SelectedValue.ToString()),
    int.Parse(drpRank.SelectedValue.ToString()),int.Parse(drpRight.SelectedValue.ToString()));
    if( re!=-1)
    {
    ShowMsg("保存成功!");
    }
    else
    {
    ShowMsg("保存失败,记录已存在!");
    }
    }
    private void ShowMsg(string msg)
    {
    Response.Write("<script>alert('"+msg+"');</script>");
    }
    }
    }
      

  8.   

    把this.btnSave.Click += new System.EventHandler(this.btnSave_Click);放到private void InitializeComponent()中去。
      

  9.   

    而且要放到this.Load += new System.EventHandler(this.Page_Load);的前面。
      

  10.   

    我已经是放到this.Load += new System.EventHandler(this.Page_Load);的前面
    可是还不会执行Button的单击事件呢?