How to give Error Message for the Button second time Click event in C#
-
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
-
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
-
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
-
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.
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
-
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
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
-
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