Link to home
Start Free TrialLog in
Avatar of dba123
dba123

asked on

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

Avatar of JimBrandley
JimBrandley
Flag of United States of America image

Try:
btnSaveQuote.Invalidate();

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

Jim
Avatar of dba123
dba123

ASKER

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'      
Avatar of dba123

ASKER

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;
            }
That should do it. The code that enabled the SaveQuote button didn't appear in the first post.
Vee_Mod - I have no objection - dba123 solved his own problem. You may cloase it now if you like.

Jim
ASKER CERTIFIED SOLUTION
Avatar of Vee_Mod
Vee_Mod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial