I keep getting the following error message at compile time: “The name ‘Message’ does not exist in the current context”. All I’m trying to do is pop up a message box. Here are my namespaces declared at the top of my code behind page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
And here is my code to show a message on a button click:
protected void EmailAbout_Click(object sender, EventArgs e)
{
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Exception Handling Test";
myMessage.Body = "Test message body";
myMessage.From = new MailAddress("me@yourprovider.com");
myMessage.To.Add(new MailAddress("you@yourprovider.com"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
Message.Text = "Message sent";
}
Is this a case of a missing namespace? It seems so basic yet I can’t figure it out? Thanks in advance!
Here is the markup page:
<%@ Page Title="About SalesPro" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="About.aspx.cs" Inherits="WebApplication2.About" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
About, Inc.
</h2>
<p>
Some Stuff here...
</p>
<p>
<asp:Button ID="EmailAbout" runat="server" Text="Email Information"
onclick="EmailAbout_Click" />
</p>
</asp:Content>
You need the javaScript-function “alert()” 🙂
Try this: