Solved

ASP.NET C# message box

Posted on 2006-06-27
3
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

626 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