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 に答える