Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to give Error Message for the Button second time Click event in C#

How to give Error Message for the Button second time Click event in C#

Scheduled Pinned Locked Moved C#
csharphelptutorialquestionasp-net
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ChandrakanthGaddam
    wrote on last edited by
    #1

    Hi, This is from Chandrakanth. Working on asp.net with C#. Actually my problem is ... When i click first time the process is going on... and button1 shold be enable. Problem is.... if i click the button second time while process going on time, i should display error message. How can i go for that? Can any one give me some example on this Thanks and Regards Chandrakanth

    D A 2 Replies Last reply
    0
    • C ChandrakanthGaddam

      Hi, This is from Chandrakanth. Working on asp.net with C#. Actually my problem is ... When i click first time the process is going on... and button1 shold be enable. Problem is.... if i click the button second time while process going on time, i should display error message. How can i go for that? Can any one give me some example on this Thanks and Regards Chandrakanth

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Instead, why not disable the button while the execution is going on?

      The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures." जय हिंद

      1 Reply Last reply
      0
      • C ChandrakanthGaddam

        Hi, This is from Chandrakanth. Working on asp.net with C#. Actually my problem is ... When i click first time the process is going on... and button1 shold be enable. Problem is.... if i click the button second time while process going on time, i should display error message. How can i go for that? Can any one give me some example on this Thanks and Regards Chandrakanth

        A Offline
        A Offline
        ABitSmart
        wrote on last edited by
        #3

        why don't you disable the button when the user first clicks ? (and enable it when the processing completes) Disabling will make the processing implied rather than clicking and then being informed.

        C 1 Reply Last reply
        0
        • A ABitSmart

          why don't you disable the button when the user first clicks ? (and enable it when the processing completes) Disabling will make the processing implied rather than clicking and then being informed.

          C Offline
          C Offline
          ChandrakanthGaddam
          wrote on last edited by
          #4

          Hi, From Chandrakanth.. Thnaks for your reply. Actually we shold not disable that button. ' We have to display error message . Requirement is like that. If any suggestions please give me message... Thanks and Regards Chandrakanth

          D 1 Reply Last reply
          0
          • C ChandrakanthGaddam

            Hi, From Chandrakanth.. Thnaks for your reply. Actually we shold not disable that button. ' We have to display error message . Requirement is like that. If any suggestions please give me message... Thanks and Regards Chandrakanth

            D Offline
            D Offline
            dojohansen
            wrote on last edited by
            #5

            There is nothing Holy about requirements and when they are nonsensical it might be better for everyone if you suggest an improvement to the relevant stakeholders. That said, all the information you need to code this is to know if the process is running or not. Since only two states are possible, a bool is fitting: bool running; With this new state available, you need to set it true when the process starts, false when it ends, and then in your event handler take different courses of action depending on the state of this flag. It really is that simple. (A general hint: This approach, asking yourself "what information do I need?" first, very often makes solutions to simple problems appear almost automatically.)

            void btnRun_click(object sender, EventArgs e)
            {
            if (btnRun.Tag != null)
            MessageBox.Show("Not now you idiot, I'm busy.");
            else
            ThreadPool.QueueUserWorkItem(new WaitCallback(process));
            }

            void process(object state)
            {
            running = true;
            // Use try-finally so the flag is updated even if an exception occurs.
            try
            {
            ...
            }
            finally
            {
            running = false;
            }
            }

            (The "object state" parameter is required to conform to the WaitCallback delegate signature - you may of course also use it to actually pass information to the method if convenient.) Hope this helps, Dag

            D 1 Reply Last reply
            0
            • D dojohansen

              There is nothing Holy about requirements and when they are nonsensical it might be better for everyone if you suggest an improvement to the relevant stakeholders. That said, all the information you need to code this is to know if the process is running or not. Since only two states are possible, a bool is fitting: bool running; With this new state available, you need to set it true when the process starts, false when it ends, and then in your event handler take different courses of action depending on the state of this flag. It really is that simple. (A general hint: This approach, asking yourself "what information do I need?" first, very often makes solutions to simple problems appear almost automatically.)

              void btnRun_click(object sender, EventArgs e)
              {
              if (btnRun.Tag != null)
              MessageBox.Show("Not now you idiot, I'm busy.");
              else
              ThreadPool.QueueUserWorkItem(new WaitCallback(process));
              }

              void process(object state)
              {
              running = true;
              // Use try-finally so the flag is updated even if an exception occurs.
              try
              {
              ...
              }
              finally
              {
              running = false;
              }
              }

              (The "object state" parameter is required to conform to the WaitCallback delegate signature - you may of course also use it to actually pass information to the method if convenient.) Hope this helps, Dag

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              I had a thought of threads. But I did not felt writing this much wothy enough if enabling disabling alone could do.

              The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures." जय हिंद

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups