このコードは、フォームの送信ボタンがクリックされると、これらのフォーム文字列を電子メールとして送信する必要があります。ただし、「EcampusIssuesSubmit.Click」で「handles 句には withevents 変数が必要です」というエラーが表示されます。詳細は次のとおりです。
- Microsoft の msdn によると、「WithEvents 変数」を追加する必要がありますが、これまではその必要はありませんでした。
- 通常、Visual Studio でボタン フォーム コントロールをクリックするとコード ファイル ページが表示されますが、ここでは「アクションを完了できませんでした」というメッセージが表示されます。
念のため asp コードを含めましたが、それがエラーの原因ではないと思います。
VBコードは次のとおりです。
System.Net.Mail をインポートします
Partial Public Class EcampusMain Inherits System.Web.UI.Page Protected Sub EcampusIssuesSubmit_Click(sender As Object, e As EventArgs) Handles EcampusIssuesSubmit.Click ' Gather Variables Dim strfirstname As String = "First Name: " + firstname.Text Dim strlastname As String = "Last Name: " + lastname.Text Dim strnetid As String = "NetID: " + netid.Text Dim struin As String = "UIN: " + uin.Text Dim strphone As String = "Phone Number: " + phone.Text Dim strcurrentdate As String = "Date: " + currentdate.Text Dim strissueday As String = "Date of Issue: " + issueday.Text Dim strinstructorname As String = "Faculty/Instructor Name:" + instructorname.Text Dim stremail As String = "E-mail: " + email.Text Dim strcontactpref As String = "Preferred way to contact: " + contactpref.Text Dim strecampSect As String = "ECampus Class Name & Section:" + ecampSect.Text Dim strbldanroom As String = "Building & Room Number: " + bldanroom.Text Dim strcomputer As String = "Computer Number:" + computer.Text Dim strbrowser As String = "Web browser being used: " + browser.Text Dim strproblem As String = "problem Description: " + problem.Text Dim strhumanity As String = humanity.Text ' E-mail Prep Dim body As String = strfirstname & strlastname & strnetid & struin & strphone & strissueday & strinstructorname & stremail & strecampSect & strcomputer & strproblem Dim ourEmail As String = "Eforms@website.edu" 'Change back ' Check the humanity of the submitter ' Change back Turtles! If strhumanity = "Turtles!" Then ' Send Email Using message As New MailMessage() message.From = New MailAddress(ourEmail.ToString()) message.[To].Add(New MailAddress("george123@yahoo.com")) 'Change back message.Subject = "Ecampus Isses" message.Body = body Dim client As New SmtpClient() client.Host = "127.0.0.1" 'Change back client.Send(message) End Using Else 'exit End If End Sub End Class
ここにaspコードがあります
<%@ Page Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="EcampusIssue.aspx.vb" Inherits="_Default" %> <asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" Runat="Server"> <style type="text/css"> .auto-style1 { text-align: center; } .auto-style2 { text-align: center; } </style> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server"> <center> <div> <h1 style="font-size: xx-large; text-align: center"> Ecampus Problem Report</h1> <h2 style="font-size: x-large; text-align: left"> <strong>Student/Faculty Contact Information</strong></h2> <p class="auto-style2"> First Name<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="firstname" runat="server" Width="400"></asp:TextBox> <o:p></o:p> </p> <asp:RequiredFieldValidator id="vfirstname" runat="server" ControlToValidate="firstname" ErrorMessage="This is a required item." ForeColor="Red"> </asp:RequiredFieldValidator> <p class="auto-style2"> Last Name<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="lastname" runat="server" Width="400"></asp:TextBox> <o:p></o:p> </p> <asp:RequiredFieldValidator id="vlastname" runat="server" ControlToValidate="lastname" ErrorMessage="This is a required item." ForeColor="Red"> </asp:RequiredFieldValidator> <p class="auto-style2"> NetID<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="netid" runat="server" Width="400"></asp:TextBox> <o:p></o:p> </p> <asp:RequiredFieldValidator id="vnetid" runat="server" ControlToValidate="netid" ErrorMessage="This is a required item." ForeColor="Red"> </asp:RequiredFieldValidator> <p class="auto-style2"> UIN<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="uin" runat="server" Width="400"></asp:TextBox> <o:p></o:p> </p> <asp:RequiredFieldValidator id="vuin" runat="server" ControlToValidate="uin" ErrorMessage="This is a required item." ForeColor="Red"> </asp:RequiredFieldValidator> <p class="auto-style2"> Phone Number<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="phone" runat="server" Width="250px"></asp:TextBox> <o:p></o:p> </p> <asp:RequiredFieldValidator id="vphone" runat="server" ControlToValidate="phone" ErrorMessage="This is a required item." ForeColor="Red"> </asp:RequiredFieldValidator> <p class="auto-style2"> Date<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="currentdate" runat="server" Width="249px"></asp:TextBox> <o:p></o:p> </p> <p class="auto-style2"> Date of Issue<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="issueday" runat="server" Width="250px"></asp:TextBox> <o:p></o:p> </p> <p class="auto-style2"> Faculty/Instructor Name<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="instructorname" runat="server" Width="400"></asp:TextBox> <o:p></o:p> </p> <asp:RequiredFieldValidator id="vinstructorname" runat="server" ControlToValidate="instructorname" ErrorMessage="This is a required item." ForeColor="Red"> </asp:RequiredFieldValidator> <p class="auto-style2"> Your E-mail<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="email" runat="server" Width="400"></asp:TextBox> <o:p></o:p> </p> <asp:RequiredFieldValidator id="vemail" runat="server" ControlToValidate="email" ErrorMessage="This is a required item." ForeColor="Red"> </asp:RequiredFieldValidator> <p class="auto-style2"> Preferred way to contact you?<o:p></o:p></p> <p class="auto-style1"> <asp:RadioButtonList ID="contactpref" runat="server" BorderWidth="0px" Font-Bold="False" Font-Size="X-Small" Height="44px" Width="85px"> <asp:ListItem>E-mail</asp:ListItem> <asp:ListItem>Phone</asp:ListItem> </asp:RadioButtonList> <o:p></o:p> </p> <p class="auto-style2"> ECampus Class Name & Section<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="ecampSect" runat="server" Width="400"></asp:TextBox> <o:p></o:p> </p> <asp:RequiredFieldValidator id="vecampSect" runat="server" ControlToValidate="ecampSect" ErrorMessage="This is a required item." ForeColor="Red"> </asp:RequiredFieldValidator> <p class="auto-style1"> Building & Room Number<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="bldanroom" runat="server" Width="301px"></asp:TextBox> <o:p></o:p> </p> <p class="auto-style1"> Computer Number<o:p>:</o:p></p> <p class="MsoNormal"> <asp:TextBox ID="computer" runat="server" Width="201px"></asp:TextBox> <o:p></o:p> </p> <p class="auto-style1"> Web browser being used<o:p>:</o:p></p> <p class="auto-style1"> <asp:DropDownList ID="browser" runat="server" Height="16px" Width="300px"> <asp:ListItem>FireFox</asp:ListItem> <asp:ListItem>Chrome</asp:ListItem> <asp:ListItem>Internet Explorer</asp:ListItem> <asp:ListItem>Opera</asp:ListItem> <asp:ListItem>Other(Include in description)</asp:ListItem> </asp:DropDownList> <o:p></o:p> </p> <p class="auto-style1"> Please describe your issue:<o:p></o:p></p> <p class="MsoNormal"> <asp:TextBox ID="problem" runat="server" Width="400px" Height="200px"></asp:TextBox> </p> <p class="MsoNormal"> <asp:RequiredFieldValidator id="vproblem" runat="server" ControlToValidate="problem" ErrorMessage="This is a required item." ForeColor="Red"> </asp:RequiredFieldValidator> <br /> Please verify your humanity by typing "Aggies!" in the box below (case sensative):<br /> <asp:TextBox ID="humanity" runat="server"></asp:TextBox> <o:p> <br /> <asp:Button ID="SciFairSubmit" runat="server" Text="Submit" /> </o:p> </p> </div> </center> </asp:Content>