遵循教程后的ASP.Net警告和错误-需要帮助



我在上网络编程课,我们目前的作业必须使用ASP.Net完成。我感到沮丧的问题和原因是我的教授缺乏教学,方向不明确,"指南"过时。我使用的是2012版的Visual Studio Ultimate。

我应该制作一个与这个"指南"完全不同的程序,但当我出现所有这些错误/警告时,我不知道该怎么做,正如他的指南所示。

在他写得很差的指南中。。他说:"调试后会出现一些错误。修复它们,你的网页就会显示出来。"然而,使用他的代码并像他一样遵循一切。。我有52个错误和3个警告。我在谷歌上搜索了大部分,只找到了Q&一个针对其他人项目的特定问题。

代码不多,我不明白为什么复制我的教授代码/指南会有这么多错误。我将添加一些错误/警告,然后添加下面文件中的代码。如果有人能帮我纠正其中的一些错误,我将不胜感激。谢谢!

3个警告:

Warning 34  Function without an 'As' clause; return type of Object assumed.     \vmware-hostshared foldersDocumentsVisual Studio     2012WebSitesCS316Program5game.aspx.vb   26  14  CS316Program5(1)
Warning 50  Function without an 'As' clause; return type of Object assumed. \vmware-hostshared foldersDocumentsVisual Studio     2012WebSitesCS316Program5game.aspx.vb   58  14  CS316Program5(1)
Warning 53  Function without an 'As' clause; return type of Object assumed. \vmware-hostshared foldersDocumentsVisual Studio 2012WebSitesCS316Program5game.aspx.vb   91  14  CS316Program5(1)

52个错误中的一些:(

Error   1   'Context' is not a member of 'game'.    C:UsersJustin   GeisAppDataLocalTempTemporary ASP.NET   Filesroot95a4297024c7c528App_Web_mrk1wbiu.0.vb    128 
Error   3   Class 'game_aspx' must implement 'ReadOnly Property IsReusable As     Boolean' for interface 'System.Web.IHttpHandler'. Implementing property must have matching     'ReadOnly' or 'WriteOnly' specifiers.  C:UsersJustin GeisAppDataLocalTempTemporary     ASP.NET Filesroot95a4297024c7c528App_Web_mrk1wbiu.0.vb    144 
Error   4   Class 'game_aspx' must implement 'Sub ProcessRequest(context As HttpContext)' for interface 'System.Web.IHttpHandler'.  C:UsersJustin GeisAppDataLocalTempTemporary ASP.NET Filesroot95a4297024c7c528App_Web_mrk1wbiu.0.vb    144 
Error   5   'GetWrappedFileDependencies' is not a member of 'ASP.game_aspx'.    C:UsersJustin GeisAppDataLocalTempTemporary ASP.NET Filesroot95a4297024c7c528App_Web_mrk1wbiu.0.vb    163 
Error   6   'Server' is not a member of 'ASP.game_aspx'.    C:UsersJustin GeisAppDataLocalTempTemporary ASP.NET Filesroot95a4297024c7c528App_Web_mrk1wbiu.0.vb    166 
Error   7   property 'SupportAutoEvents' cannot be declared 'Overrides' because it does not override a property in a base class.    C:UsersJustin GeisAppDataLocalTempTemporary ASP.NET Filesroot95a4297024c7c528App_Web_mrk1wbiu.0.vb    169 
Error   8   Value of type 'ASP.game_aspx' cannot be converted to 'System.Web.UI.Page'.  C:UsersJustin GeisAppDataLocalTempTemporary ASP.NET Filesroot95a4297024c7c528App_Web_mrk1wbiu.0.vb    230 

游戏.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="game.aspx.vb" Inherits="game" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Customer Data</title>
</head>
<body>
<form id="form1" runat="server">
    Name:
    <asp:TextBox ID="username" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator runat="server" ControlToValidate="username" ErrorMessage="name required"></asp:RequiredFieldValidator>
    <br />
    <asp:Button ID="Button1" onClick="nameEntered" runat="server" Text="Submit" />
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <h1>
        <asp:Label ID="pageloaded" runat="server" Text=""></asp:Label>
    </h1>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" Visible="false">
        <ContentTemplate>
            <br />
            Zip Code:
            <asp:TextBox ID="Zip" runat="server" AutoPostBack="true" OnTextChanged="ZipChanged"></asp:TextBox>
            <asp:Label ForeColor="Red" ID="errormessage" runat="server" Text=" ">        </asp:Label>
            <br />
            Address:
            <asp:TextBox ID="Address" AutoPostBack="true" runat="server"></asp:TextBox>
            <asp:Label ForeColor="Red" ID="errormessage2" runat="server" Text=" ">    </asp:Label>
            <br />
            City:
            <asp:TextBox ID="City" runat="server"></asp:TextBox>
            <br />
            State:
            <asp:TextBox ID="State" runat="server"></asp:TextBox>
            <asp:Label ID="updatemessage" runat="server" Text=""></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>

game.aspx.vb

' game.aspx.vb
' asp.net vb.net example
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
' code behind is in a class like this
' the name customer must match the name in the inherits
' attribute of the page directive at the top of the aspx file
Partial Class customer
Inherits System.Web.UI.Page
' zipchanged executed when user clicks in address textbox
Function ZipChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    ' verify that user entered 5 digits for zip code 
    ' using regualr expression pattern matching
    Dim myMatch As Match = System.Text.RegularExpressions.Regex.Match(Zip.Text, "^d{5}$")
    ' if 5 digits entered
    If myMatch.Success Then
        errormessage.Text = "" ' blank out any previous error message
        updatemessage.Text = "City/State updated at " + DateTime.Now.ToString()
        ' VB case (select/switch) statement
        Select Case Zip.Text  ' select on zip code entered
            Case "40502"
                ' update text boxes
                City.Text = "Lexington"
                State.Text = "KY"
            Case "60609"
                City.Text = "Chicago"
                State.Text = "IL"
            Case Else  ' entered zip code not found
                City.Text = ""
                State.Text = ""
                updatemessage.Text = "Unknown zip code"
        End Select
    Else  ' invalid zip code entered
        errormessage.Text = "zip code must be 5 digits"
        City.Text = ""
        State.Text = ""
        updatemessage.Text = ""

    End If
End Function
' Page_Load executed whenever page is loaded by user
Function Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ' Page.IsPostBack is used to check if this is
    ' the first load of the page (not an Ajax update)
    If Not Page.IsPostBack Then
        ' first load - not Ajax update of page
        Dim I As Integer  ' iterator for cookie search
        Dim foundcookie As Boolean = False ' flag if cookie found
        Dim currenttime As String ' current time kept here
        currenttime = DateTime.Now.ToString()
        ' Running on your local PC cookies kept
        ' under "localhost". Iterate thru all local cookies. 
        For I = 0 To Request.Cookies.Count - 1
            ' If not first execution within 24 hours
            ' the time was put in a cookie named LastAccess
            If Request.Cookies.Item(I).Name = "LastAccess" Then
                foundcookie = True
                ' Get the cookie value and display to user
                pageloaded.Text = "Page last loaded at: " +  Request.Cookies.Item(I).Value
            End If
        Next
        If Not foundcookie Then
            pageloaded.Text = "First load of page at: " + currenttime
        End If
        ' Save current time in a cookie named LastAccess
        Dim myCookie As New HttpCookie("LastAccess")
        ' cookie value
        myCookie.Value = currenttime
        ' cookie expires in 24 hours
        myCookie.Expires = DateTime.Now.AddHours(24)
        ' now add the cookie (name in myCookie: LastAccess)
        Response.Cookies.Add(myCookie)
    End If ' if not first load of page
End Function
Function nameEntered(ByVal sender As Object, ByVal e As System.EventArgs)
    Button1.Text = "Clicked"
    UpdatePanel1.Visible = True
End Function
End Class

Web.Config

<?xml version="1.0"?>
<configuration>
    <system.web>
      <compilation debug="true" strict="false" explicit="true" targetFramework="4.5.1" />
      <httpRuntime targetFramework="4.5.1" />
    </system.web>
  <appSettings>
    <add key="webpages:Enabled" value="true"/>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
  </appSettings>
  <system.webServer>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

这里缺少一些代码。

类背后的代码game.aspx.vb在game.aspx:-顶部的页面声明中被引用

CodeFile="game.aspx.vb" Inherits="game"

但是game.aspx.vb中的类名为customer?这行不通。页面声明的"inherits"部分明确表示它正在寻找一个名为"game"的类。

此外,您的一些错误与IHttpHandler实现有关:-

Error   3   Class 'game_aspx' must implement 'ReadOnly Property IsReusable As     Boolean' for interface 'System.Web.IHttpHandler'... (snip)

显然,这些是在一个名为game_aspx的类中,而这个类不在您发布的任何内容中。

你的讲师试图在你还没有看到事情如何正常运转之前,就让你解决愚蠢和令人困惑的问题。这是一种愚蠢的教学方式,尤其是当他向你展示一大堆你可能从未见过的概念时。

我为你感到难过。没有人应该忍受如此糟糕的教学质量。

不管怎样,如果你能把剩下的代码挖出来发布,我可能会帮上忙。

最新更新