我 在页面类中定义了一个私有数据 在初始化的时候复值,以便我后来使用。我是想在点‘保存’按钮的时候 判断数据是否改变,弹出提示框。
页面类中的私有数据,和保存按钮中定义的局部变量 比较 ,来判断是否改变了数据。
我的问题是不能正确的提示,会不会是页面中的类和在其他的地方不一样啊
Employee Em = new Employee();   //这是全局的对象
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
      {
          init();
       }
        
}

解决方案 »

  1.   

    public partial class SCS002 : System.Web.UI.Page
    {
        /*赋值给一个对象存储信息*/
        Employee Em = new Employee();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                init();
            }
            
        }
        /*执行初始化操作*/
        private void init()
        {
             //存储传递过来的参数的值
            ViewState["s_emCode"] = "";
            //判断传递过来的参数的值是不是默认值
            if (Request.QueryString["value"].ToString() != "000")
            {//执行‘修改’操作
                string ID =  Request.QueryString["value"].ToString().Trim();
                ViewState["s_emCode"] = ID;/*无用*/
                //sql语句
                string comText = "";
                /*对dropdownlist的操作(begin)*/
                //对职务1进行绑定
                   ......
                  Em._job1 = this.dlEmJob1.SelectedValue;
                //对职务2进行绑定
                   ......
                  Em._job2 = this.dlEmJob1.SelectedValue;
                //对职务3进行绑定
                  .....
                Em._job3 = this.dlEmJob3.SelectedValue;
                //对职务4进行绑定
                comText = @"select 
                                    case  when emJob4 = 'A20' then '系统开发' 
                                      when emJob4 = 'A10' then '系统测试'
                                      when emJob4 = 'A30' then '系统设计'
                                      when emJob4 = 'A40' then '系统分析'
                                      when emJob4 = 'A50' then '专案经理'
                                      when emJob4 = 'A80' then '美工设计'
                                      when emJob4 = 'A90' then '系统管理员'
                                      when emJob4 = 'A70' then '高阶主管'
                                    end as emJob4  
                                    from emBasInfo where emCode = '" + ID + "'";
                setDropDownList(this.dlEmJob4, "emJob4", comText, "emBasInfo");
                Em._job4 = this.dlEmJob4.SelectedValue;
                //对职务5进行绑定
                ......
                Em._job5 = this.dlEmJob5.SelectedValue;
                //对职称进行绑定
                  ......
                  Em._postion = this.dlEmPostion.SelectedValue;
                //对性别进行绑定
                 ......
                Em._sex = this.dlEmIsSex.SelectedValue;
                //对员工状态进行绑定
                ......  
                Em._status = this.dlEmStatus.SelectedValue;
                /*对dropdownlist的操作(end)*/
                /*其他数据的显示(begin)*/
                comText = "select emCode,emEngName,emChName,emApptionTm,emCoverTm,emBirth,emPhone,emMSN,emEmail from emBasInfo where emCode = '" + ID + "'";
                SqlDataReader sdr = sqlHelper.get_DataReader(comText);
                if(sdr.Read())
                {
                    Em._id = this.tbEmCode.Text = sdr.GetValue(0).ToString();
                    Em._enName = this.tbEmEngName.Text = sdr.GetValue(1).ToString();
                    Em._chName = this.tbEmChName.Text = sdr.GetValue(2).ToString();
                    Em._apptionTm = this.tbEmApptionTm.Text = sdr.GetValue(3).ToString();
                    Em._coverTm = this.tbEmCoverTm.Text = sdr.GetValue(4).ToString();
                    Em._birth = this.tbEmBirth.Text = sdr.GetValue(5).ToString();
                    Em._phone = this.tbEmPhone.Text = sdr.GetValue(6).ToString();
                    Em._msn = this.tbEmMSN.Text = sdr.GetValue(7).ToString();
                    Em._email = this.tbEmEmail.Text = sdr.GetValue(8).ToString();
                }
                /*其他数据的显示(end)*/
            }
            else
            {
                this.tbEmCode.ReadOnly = false;
                setDropDownList(this.dlEmJob1, "emJob1"," " , " ");
                setDropDownList(this.dlEmJob2, "emJob2", " ", " ");
                setDropDownList(this.dlEmJob3, "emJob3", " ", " ");
                setDropDownList(this.dlEmJob4, "emJob4", " ", " ");
                setDropDownList(this.dlEmJob5, "emJob5", " ", " ");
                setDropDownList(this.dlEmPostion, "emPosition", " ", "");
                setDropDownList(this.dlEmIsSex, "emIsSex", " ", "");
                setDropDownList(this.dlEmStatus, "emStatus", " ", "");
            }
        }
        /// <summary>
        /// 从数据库中取出数据赋值给DropDownList,并动态添加一些选项
        /// </summary>
        /// <param name="id">DropDownList 的ID</param>
        ///<param name="dateField">DropDownList 绑定的数据字段</param>
        /// <param name="comText">sql语句</param>
        ///  <param name="sqlTableName">sql语句访问的表名</param>
           /*保存*/
        protected void btnSave_Click(object sender, EventArgs e)
        {        //如果格式错误推出此操作
            if (false == isVisable())
            {
                return;
            }
            if (Request.QueryString["value"].ToString() != "000")                //在修改的状态下执行 一下操作
            {
                Employee em = new Employee();
                em._id = this.tbEmCode.Text;
                em._enName = this.tbEmEngName.Text;
                em._chName = this.tbEmChName.Text;
                em._job1 = this.dlEmJob1.SelectedValue;
                em._job2 = this.dlEmJob2.SelectedValue;
                em._job3 = this.dlEmJob3.SelectedValue;
                em._job4 = this.dlEmJob4.SelectedValue;
                em._job5 = this.dlEmJob5.SelectedValue;
                em._email = this.tbEmEmail.Text;
                em._msn = this.tbEmMSN.Text;
                em._phone = this.tbEmPhone.Text;
                em._postion = this.dlEmPostion.SelectedValue;
                em._sex = this.dlEmIsSex.SelectedValue;
                em._status = this.dlEmStatus.SelectedValue;
                em._coverTm = this.tbEmCoverTm.Text;
                em._apptionTm = this.tbEmApptionTm.Text;
                em._birth = this.tbEmBirth.Text;
                //注此处意
                if ( Em.Equals(em) == false)
                {
                    this.btnSave.Attributes.Add("onClick", "javascript:return confirm('确定修改吗?');");
                    //string comText = @"update emBasInfo set emEngName = '" + this.tbEmEngName.Text + "',emChName = '" + this.tbEmChName.Text + "',emCoverTm='" + this.tbEmCoverTm.Text;            }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), DateTime.Now.ToString(), "alert('数据没有修改')", true);
                    return;
                }
            }
            else                                                                                                    //在新增情况下执行以下操作
            {        }
        }
        /*重置*/
        protected void btnReset_Click(object sender, EventArgs e)
        {    }
        /*返回*/
        protected void btnReturn_Click(object sender, EventArgs e)
        {
        }
            /// <summary