Button disable doesn´t work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • guilherme21922
    New Member
    • Jan 2008
    • 28

    Button disable doesn´t work

    [code=cpp]
    protected void btnTest_Click(o bject sender, EventArgs e)
    {
    btnTest.Enabled = false;

    //here is some code - that code take 15seconds

    //and in the end i put the button n enabled
    btnTest.Enabled = true;

    }[/code]

    i don´t know why that happen...
    when i click again the event accumulate!!!!
    i don´t know...is there some property that need to be set?

    thanks
    Last edited by Frinavale; Apr 14 '08, 07:32 PM. Reason: added [code] tags
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Do you set the Enabled property in the Page Load event anywhere? The Page Load event will be hit before your button click event when the button is clicked.

    Nathan

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Is this a web or windows application?

      You are remembering that you enabled the button at the end of your function right? So it's not going to stay disabled.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        The code that takes 15seconds to complete....is it run in a thread?

        Comment

        • guilherme21922
          New Member
          • Jan 2008
          • 28

          #5
          Originally posted by nateraaaa
          Do you set the Enabled property in the Page Load event anywhere? The Page Load event will be hit before your button click event when the button is clicked.

          Nathan
          No...i do not set the enabled property in the Page Load

          Comment

          • guilherme21922
            New Member
            • Jan 2008
            • 28

            #6
            Originally posted by Frinavale
            The code that takes 15seconds to complete....is it run in a thread?
            The code is a web service call...

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Well, if this IS a web application, it will process that entire amount of code before returning back to the webpage.
              So it will disable the button, run the code, then re-enable the button before it even gets back to the client browser.

              If you want the button to be disabled while it's working, you're going to need to attach a javascript onclick (onclientclick in aspx code) to disable the button.
              When the page reloads after processing from the regular onclick code, it will be enabled again.

              Comment

              • guilherme21922
                New Member
                • Jan 2008
                • 28

                #8
                Originally posted by Plater
                Is this a web or windows application?

                You are remembering that you enabled the button at the end of your function right? So it's not going to stay disabled.
                Is a Web application.

                The problem i think is that by default...the button properties start with enabled...and when i call a web service my settings go away...because the postback...and the page take the initial property

                Comment

                • guilherme21922
                  New Member
                  • Jan 2008
                  • 28

                  #9
                  Originally posted by Plater
                  Well, if this IS a web application, it will process that entire amount of code before returning back to the webpage.
                  So it will disable the button, run the code, then re-enable the button before it even gets back to the client browser.

                  If you want the button to be disabled while it's working, you're going to need to attach a javascript onclick (onclientclick in aspx code) to disable the button.
                  When the page reloads after processing from the regular onclick code, it will be enabled again.
                  but the my button cannot be an asp button...correc t?

                  i think you solve my problem!

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    Any button can work.

                    Comment

                    Working...