C#: How to check if a button has been clicked before, after another button is clicked..

by forme
3 replies
How to check if a button has been clicked before, after some other button is clicked in C#..

This is my question, I have a Windows Form Application with several text boxes.
It saves the text box values to a database when a button(buttonSave) is clicked.
And Mails the details when another button(buttonMail) is clicked.
I need to check whether the "buttonSave" button has been clicked when the "buttonMail" button is clicked.

How can I do this...
#button #c#.net #check #clicked
  • Profile picture of the author forme
    Anyone ????
    {{ DiscussionBoard.errors[7303150].message }}
  • Profile picture of the author KirkMcD
    Set a flag after the Save button is clicked and check it in the Mail button.
    Or start with the Mail button disabled and enable it after the Save button is clicked.

    Come on, this isn't rocket science, think.
    And next time when you post a question at 3 AM and you don't get a quick answer, remember that most of the people on this forum are in America and are sleeping.
    {{ DiscussionBoard.errors[7303494].message }}
  • Profile picture of the author cgimaster
    Originally Posted by forme View Post

    How to check if a button has been clicked before, after some other button is clicked in C#..

    This is my question, I have a Windows Form Application with several text boxes.
    It saves the text box values to a database when a button(buttonSave) is clicked.
    And Mails the details when another button(buttonMail) is clicked.
    I need to check whether the "buttonSave" button has been clicked when the "buttonMail" button is clicked.

    How can I do this...
    Create a variable called something like:

    Code:
    bool isRunning = false
    Once the button is clicked you set it to TRUE once the function finishs running you set it back to FALSE.

    Before running any other buttons you do a check like:

    Code:
    if (isRunning)
    {
            MessageBox.Show("Please wait for the other process to complete...");
            return;
    }
    Its also a good practice if you disable the other buttons while another action is running that is dependent for the other buttons.

    For example if save must run first and nothing else should run while it is doing its job, disable all other buttons until its done.
    {{ DiscussionBoard.errors[7303513].message }}

Trending Topics