Solved

ASP.NET C# message box

Posted on 2006-06-27
3
374 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now