Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

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

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

C#
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;


}
C#
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;
          }


}
}

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?
Posted

1 solution

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

Edit:- Try it as below.

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


C#
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;
}
 
Share this answer
 
v2
Comments
priya9826 13-May-13 16:16pm    
I am already done this.But still getting the same issue.
RaisKazi 13-May-13 16:27pm    
It doesn't seen in your posted code. Anyways, try by removing return;
try
{
if (SubmitButtonStatus == false)
{
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Message", "alert('Please click submit button before clicking on Next Buton')", true);

}
priya9826 13-May-13 16:33pm    
Yes.Thats true.I did n't post the Page load part.I kept the break point in the next button method what I have observed is submitbuttonstatus value is showing as false even though I clicked the submit button and In the submit button method the value shown as true for submitbuttonstatus .
RaisKazi 13-May-13 16:43pm    
Please refer to updated solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900