|
在页面代码里,定义了全局变量,放在类里面的变量,希望能在本页面未关闭前都可以调用,但发现很奇怪的一点,当页面初始化过程中该变量被赋值,然后在完成Page_Load显示了界面之后,想在随后的页面事件如按钮的点击里再次引用到该变量,却是空值了,在调试过程中,如果将该变量定义时加static修饰符则会继续保留变量值,我的代码页如下,想实现一个页面可完成添加、编辑功能,所以,需要定义action、customerid、modelCustomer变量等
- using System;
- using System.Collections.Generic;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using FineUI;
- namespace Jazz.CRM.Customer
- {
- public partial class CustomerInfoEdit : PageBase
- {
- public int CustomerId { get; set; }
- public string Action { get; set; }
- Model.CRM.Customer modelCustomer = new Model.CRM.Customer();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- InitPage();
- }
- }
- #region InitPage页面初始化
- protected void InitPage()
- {
- InitPara();
- InitPower();
- InitEvent();
- LoadData();
- InitCtrl();
- BindData();
- }
- protected void InitPara()
- {
- CustomerId = GetQueryIntValue("CustomerId");
- Action = GetQueryStrValue("Action");
- if (string.IsNullOrEmpty(Action))
- Action = "addnew";
- }
- protected void InitPower()
- {
- string powerName = string.Empty;
- FineUI.Button btn = btnAddNew;
- CheckPowerWithButton(powerName, btn);
- }
- protected void InitEvent()
- {
- btnClose.OnClientClick = ActiveWindow.GetHideReference();
- btnAddNew.OnClientClick = Window1.GetShowReference("~/Customer/CustomerLinkManEdit.aspx", "新增联系人");
- }
- protected void LoadData()
- {
- if (CustomerId != 0 && Action == "edit")
- {
- modelCustomer = bllApp.CRMCustomer.GetModel(CustomerId);
- txtCustomerName.Text = modelCustomer.CustomerName;
- }
- }
- protected void InitCtrl()
- {
- appClass.DataRuleApp.ShowUI(ddlAvailable, "DdlAvailable", "");
- appClass.DataRuleApp.ShowUI(ddlIndustry, "DdlIndustry", "");
- appClass.DataRuleApp.ShowUI(ddlImportant, "DdlImportant", "");
- appClass.DataRuleApp.ShowUI(ddlProvince, "DdlProvince", "安徽");
- appClass.DataRuleApp.ShowUI(ddlBusiness, "DdlBusiness", "");
- appClass.DataRuleApp.ShowUI(ddlBusiStage, "DdlBusiStage", "");
- appClass.DataRuleApp.ShowUI(ddlEval, "DdlEval", "");
- appClass.DataRuleApp.ShowUI(ddlMessFrom, "DdlMessFrom", "AAA");
- }
- protected void BindData()
- {}
- protected void CtrlEnable()
- {}
- #endregion
- #region Events事件处理
- protected void btnSave_Click(object sender, EventArgs e)
- {
- SaveData();
- }
- protected void btnSaveClose_Click(object sender, EventArgs e)
- {
- SaveData();
- PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
- }
- protected void btnView_Click(object sender, EventArgs e)
- {}
- protected void btnEdit_Click(object sender, EventArgs e)
- {}
- protected void btnDelete_Click(object sender, EventArgs e)
- {}
- protected void btnImport_Click(object sender, EventArgs e)
- {}
- protected void btnExport_Click(object sender, EventArgs e)
- {}
复制代码 变量Action跟踪发现,在InitPara完成初始化赋值,在LoadData还可以保留不变,但完成Page_Load事件显示了界面之后,点击Save按钮调用SaveData时发现Action还是恢复原有的null值了
不明所以,请路过的大师指点,如何处理
|
|