Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

ASP.NET C# message box

I'm a VB.NET guy, but I need to create a message box using C# once a button is clicked.  How do I go about doing that?


Here's the code:

private void Button1_Click(object sender, System.EventArgs e)
            {
                  string body = txtMessage.Text.Trim();
                  Mail.SendMail(MailInfo.SmtpServer, MailInfo.MailFrom, MailInfo.MailTo, string.Empty, MailInfo.Subject, body);
                  MessageBox.Show("My message box text.");
            }
0
scross1276
Asked:
scross1276
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
Client-side or server-side messagebox ? What you have currently is a server-side messagebox, which (as far as I am aware) will simply be ignored since a messagebox on the server is of little use.
0
 
scross1276Author Commented:
Ah, client-side.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Ok, basically you have two options based on whether you want to display a message box at the start or end of the process.

To show an alert first, before the server-side click is handled you can add a script to the button:

    <asp:Button ID="Button1" runat="server" OnClientClick="alert('Button clicked')" />

To show an alert after the server-side click is handled:

    private void Button1_Click(object sender, System.EventArgs e)
    {
       string body = txtMessage.Text.Trim();
       Mail.SendMail(MailInfo.SmtpServer, MailInfo.MailFrom, MailInfo.MailTo, string.Empty, MailInfo.Subject, body);

       Response.Write("<script language=\"javascript\">alert('Button clicked from server');</script>");
    }
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now