我在编译时不断收到以下错误消息:“名称'消息'在当前上下文中不存在”。我要做的就是弹出一个消息框。这是在我的代码隐藏页面顶部声明的命名空间:
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;
这是我在单击按钮时显示消息的代码:
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";
}
这是缺少命名空间的情况吗?它看起来很基础,但我无法弄清楚?提前致谢!
这是标记页面:
<%@ 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>