コンパイル時に次のエラー メッセージが表示され続けます: 「名前 'Message' は現在のコンテキストに存在しません」私がやろうとしているのは、メッセージボックスをポップアップすることだけです。コードビハインドページの上部で宣言されている名前空間は次のとおりです。
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>