0

一旦单击表单上的提交按钮,此代码应将这些表单字符串作为电子邮件发送。但是“EcampusIssuesSubmit.Click”给出了错误“handles 子句需要 withevents 变量”。以下是更多细节:

  • 根据微软的 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 &amp; 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 &amp; 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>
                &nbsp;&nbsp;&nbsp;
            </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 &quot;Aggies!&quot; 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>
    
4

1 回答 1

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

部分听起来像你有一个范围问题,所以下一个错误可能是点击事件将无法找到新的子EcampusSendIssue和/或新的子将无法找到名字,姓氏等。但至少你会知道问题出在哪里 - 如果不了解更多关于它的结构,很难说

于 2013-10-11T18:02:27.547 回答