0

您好我正在尝试更改 Global.asax 之外的 Application 变量的变量,但之前的数据似乎再次出现。有什么办法可以更改变量的值或重置它。谢谢 ...

In Global.asax :

 void Application_Start(object sender, EventArgs e)
 {
    Application["abc"] = "";
 }

In  aspx.cs page :

protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      ViewState["countmsg"] = 0;
   }
}

protected void Button1_Click(object sender, EventArgs e)
{
   ViewState["countmsg"] = Convert.ToInt32(ViewState["countmsg"]) +1;
   Application["abc"] = Application["abc"] + "hello" + Environment.NewLine;
   string str = Application["abc"].ToString();
     if (Convert.ToInt32(ViewState["countmsg"]) >= 4)
     {
        Application["abc"] = "";    // here the reset is not working
        ViewState["countmsg"] = 0;
     }
}
4

1 回答 1

0
protected void Button1_Click(object sender, EventArgs e)
{
  ViewState["countmsg"] = Convert.ToInt32(ViewState["countmsg"]) +1;
  Application["abc"] = Application["abc"] + "hello" + Environment.NewLine;
  string str = Application["abc"].ToString();

   if (Convert.ToInt32(ViewState["countmsg"]) >= 4)
   {
    Application.Lock();
    Application["abc"] = "";    // now its working
    Application.UnLock();  
    ViewState["countmsg"] = 0;
  }
}
于 2012-11-30T06:05:42.307 回答