我在网络编程课程中,我们当前的任务必须使用ASP.Net完成。我沮丧的问题和原因是由于我的教授缺乏教学,方向不明确,以及过时的“指南”。我正在使用2012版的Visual Studio Ultimate。
我应该制作一个完全不同的程序,而不是这个“指南”,但我不知道当我将所有这些错误/警告完全按照他的指南显示时,我应该怎么做。
在他写得不好的指南中......他说:“在调试时会出现一些错误。修复它们,你的网页就会显示出来。”然而,使用他的代码并遵循他所做的一切......我有52个错误和3个警告。我在Google上搜索了大部分内容,并且只为其他人的程序找到了Q& A特定问题。
没有太多的代码,我不知道复制我的教授代码/指南有多少错误。我将添加一些错误/警告,然后从下面的文件中添加代码。如果有人可以帮我解决其中的一些错误,我会非常感激。谢谢!
Warning 34 Function without an 'As' clause; return type of Object assumed. \\vmware-host\shared folders\Documents\Visual Studio 2012\WebSites\CS316Program5\game.aspx.vb 26 14 CS316Program5(1)
Warning 50 Function without an 'As' clause; return type of Object assumed. \\vmware-host\shared folders\Documents\Visual Studio 2012\WebSites\CS316Program5\game.aspx.vb 58 14 CS316Program5(1)
Warning 53 Function without an 'As' clause; return type of Object assumed. \\vmware-host\shared folders\Documents\Visual Studio 2012\WebSites\CS316Program5\game.aspx.vb 91 14 CS316Program5(1)
Error 1 'Context' is not a member of 'game'. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_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:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 144
Error 4 Class 'game_aspx' must implement 'Sub ProcessRequest(context As HttpContext)' for interface 'System.Web.IHttpHandler'. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 144
Error 5 'GetWrappedFileDependencies' is not a member of 'ASP.game_aspx'. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 163
Error 6 'Server' is not a member of 'ASP.game_aspx'. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_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:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 169
Error 8 Value of type 'ASP.game_aspx' cannot be converted to 'System.Web.UI.Page'. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 230
<%@ 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
' 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
<?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>
答案 0 :(得分:0)
这里缺少一些代码,等等。
代码隐藏类 - game.aspx.vb - 在game.aspx顶部的页面声明中引用: -
CodeFile="game.aspx.vb" Inherits="game"
但是game.aspx.vb中的类被称为customer
?这不行。页面声明的“继承”部分清楚地表明它正在寻找一个名为“游戏”的类。
此外,您的一堆错误与IHttpHandler实现有关: -
Error 3 Class 'game_aspx' must implement 'ReadOnly Property IsReusable As Boolean' for interface 'System.Web.IHttpHandler'... (snip)
显然,这些是在一个名为game_aspx
的课程中,而不是你发布的任何内容。
在您了解事情如何正常运作之前,您的讲师正试图让您解决愚蠢和令人困惑的问题。这是一种愚蠢的教学方式,特别是当他向你展示你可能以前从未见过的一大堆概念时。
我为你感到难过。没有人应该遭受如此低质量的教学。
无论如何 - 如果你能挖掘出其余的代码并发布它,我也许可以提供帮助。