?
Solved

Disabling of button not working right

Posted on 2007-08-12
8
Medium Priority
?
194 Views
Last Modified: 2010-04-15
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;
            }

0
Comment
Question by:dba123
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:JimBrandley
ID: 19680458
Try:
btnSaveQuote.Invalidate();

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

Jim
0
 
LVL 1

Author Comment

by:dba123
ID: 19680477
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
 
LVL 1

Author Comment

by:dba123
ID: 19680492
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:JimBrandley
ID: 19680517
That should do it. The code that enabled the SaveQuote button didn't appear in the first post.
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 19680609
Vee_Mod - I have no objection - dba123 solved his own problem. You may cloase it now if you like.

Jim
0
 
LVL 1

Accepted Solution

by:
Vee_Mod earned 0 total points
ID: 19706948
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 21 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question