Solved

ASP.NET C# message box

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Different Delete Messages 7 37
Json and asp.net mvc 2 45
Reset asp.net login password 4 34
rebind a grid after user clicks on node in treeview 1 16
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

861 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

23 Experts available now in Live!

Get 1:1 Help Now