Disabling of button not working right

Ok, on one of my button clicks I'm calling a function.  In the function, it is validating some items then setting another button's enable to false.  I know that when I step through it gets to the part where it's disabling the other button but for some reason, button 2 still shows enabled after my first button is clicked.

So button 1 has something like this

        protected void btnCalculate_Click(object sender, System.EventArgs e)
        {
            some code and then:

            ValidateOdometer(intCancelOdom);
         }

        private void ValidateOdometer(int intCancelOdometer)
        {
           Some code and then at the end is this in this function:

            // validate
            if (intCancelOdometer < Odometer)
            {
                this.lblMsg.Text = GetMessageText("Cody", LogonUObj.TCode, CultureName);
                btnSaveQuote.Enabled = false;
            }
        }

so it gets to btnSaveQuote.Enabled = false but when debug ends, the page still continues the rest of the code in the btnCalculate_Click which I don't want.

Before I moved this all into a function, we just had this in the main logic of the btnCalculate_Click which was working fine:


            if (intCancelOdom < ContractSaleOdometer)
            {
                this.lblMsg.Text = GetMessageText("CAD", LogonUserObj.TpaCode, CultureName);
                btnSaveQuote.Enabled = false;
                return;
            }

LVL 1
dba123Asked:
Who is Participating?
 
Vee_ModCommented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0
 
JimBrandleyCommented:
Try:
btnSaveQuote.Invalidate();

To force a redraw of the whole window:
this.Invalidate();

Jim
0
 
dba123Author Commented:
the return used to work fine.  I don't know what you mean by withdraw of window.  This is a pop-up window indeed but I still want the rest of the page to load, just not the rest of the code in the button click after it validates and sets that button's enabled to false.  I just don't know why now that this is calling my new function that the same logic is not stopping the rest of the code in the first button's onclick event once it disables button 2.  I guess I'll try to put the return statement back in but I know that doesn't work anymore after moving that validation if statement into a new funciton call.

'System.Web.UI.WebControls.Button' does not contain a definition for 'Invalidate'      
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
dba123Author Commented:
Ok, sort of figured something out, I did a few things.


1) Changed my Validate function to return true or false now
2) In the btnCalculate_Click method, I wrapped this statement (which was at the end of this function), with the result check from my validate function:

            if (ValidateOdometer(intCancelOdom))
            {
                btnSaveQuote.Enabled = true;
            }
0
 
JimBrandleyCommented:
That should do it. The code that enabled the SaveQuote button didn't appear in the first post.
0
 
JimBrandleyCommented:
Vee_Mod - I have no objection - dba123 solved his own problem. You may cloase it now if you like.

Jim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.