You can try disabling the Export and Email buttons, and enabling them in the click event of the Query button. If you don't want to disable them, you can set a hidden field which will say whether the Query button has been clicked. In the click event of the Query button, set the hidden field value. On ClientClick
events of the Export and Email buttons, write some JScript in which you can read the hidden field value. If the value corresponds to the Query button not been clicked thus far, show an alert message to the user. If not, proceed as usual.
For Email, try the following piece of code:
protected void Buttonmail_Click(object sender, EventArgs e)
{
try
{
fn_AttachGrid();
Label1.Text="Email sent successfully";
}
catch(Exception ex)
{
Label1.Text = ex.ToString();
}
}
On Email button click, the fn_AttachGrid()
will be invoked, and if it sends out the mail successfully, will cause the success message to be shown to the user on the following line. If there's an exception, it will be caught in the catch block, and the exception message is shown to the user. As a side note, it's a good idea to show customised error messages to the user instead of the default exception message and log the exception somewhere.