一旦单击表单上的提交按钮,此代码应将这些表单字符串作为电子邮件发送。但是“EcampusIssuesSubmit.Click”给出错误“handles子句需要一个withevents变量”。以下是一些更多细节:
我已经包含了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>
答案 0 :(得分:0)
问题的至少一部分似乎是这样的:
Partial Public Class EcampusMain
Inherits System.Web.UI.Page
Protected Sub EcampusIssuesSubmit_Click(sender As Object, e As EventArgs) _
Handles EcampusIssuesSubmit.Click
“handles子句需要一个withevents变量”消息说VS认为EcampusIssuesSubmit
不是实际点击的东西,即它没有事件。或者它已被重命名或者此事件处理程序已被移动。
如果EcampusMain
与按钮所在的类不同,那么您可能已隐藏了该按钮事件。
测试这个的一种方法,也许修复它是将该事件子更改为方法:
Friend Sub EcampusSendIssue()
... all your code
End Sub
然后点击标准按钮
来调用它 Sub Button_Name_Click(sender As Object, e As EventArgs) _
Handles Button_Name.Click
EcampusSendIssue
End Sub
部分听起来你有一个范围问题,因此下一个错误可能是click事件无法找到新的子EcampusSendIssue
和/或新子将无法找到名字,姓氏等等。但至少你会知道问题是什么 - 如果不了解更多关于这种结构的原因很难说清楚