Solved

ASP.NET C# message box

Posted on 2006-06-27
3
381 Views
Last Modified: 2012-05-05
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
Comment
Question by:scross1276
  • 2
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16995429
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
 

Author Comment

by:scross1276
ID: 16995442
Ah, client-side.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 16995515
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question