布尔值不存储 [英] the Boolean value is not storing

查看:100
本文介绍了布尔值不存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我已经声明了一个bool变量,并且点击每个按钮为bool分配一些值



Hi,

I have declared a bool variable and assigning some value to the bool on click of each button

public partial class Exercise : System.Web.UI.Page
{
    //Variables
    public string strCourseType = string.Empty;
    int count=0;
    bool submitButtonStatus=false;




protected void btnSubmit_Click(object sender, EventArgs e)
   {

       if (pnlResults.Visible == true)
       {
            ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Message", "alert('Please click on next button')", true);
            return;
       }
       SubmitButtonStatus = true;





}



}

protected void btnNext_Click(object sender, EventArgs e)
  {
      try
      {
          if (SubmitButtonStatus == false)
          {
              ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Message", "alert('Please click submit button before clicking on Next Buton')", true);
              return;
          }





}

}



这里我面临的问题是即使我点击了提交按钮,bool值在下一个按钮中显示为false。

有什么想法吗?



}
}

Here the issue I am facing is "Even though I clicked on submit button ,The bool value is showing as false in the next button.
Any thoughts?

推荐答案

Page_Load()事件中初始化 submitButtonStatus 的值,然后将其放入!IsPostBack 条件。



编辑: - 尝试如下。



Initialize value of submitButtonStatus in Page_Load() event and then place it inside !IsPostBack condition.

Edit:- Try it as below.

static bool submitButtonStatus;
private void Page_Load()
{
   //Your code. Please do not initialize variable SubmitButtonStatus here. By default bool is false. 
}







protected void btnSubmit_Click(object sender, EventArgs e)
{

       if (pnlResults.Visible == true)
       {
            ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Message", "alert('Please click on next button')", true);

       }
       SubmitButtonStatus = true;
}


这篇关于布尔值不存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆