2014-08-27 48 views
0

我想学习ASP.NET(经过多年使用经典的ASP,jQuery,Ajax等)。我已经安装了VS 2010,并且在我的W7 64位个人电脑上运行了IIS。VB ASP.NET 4.0 - 将示例添加到新的Web项目

我创建了一个名为ASP.NET-4.0的新Web项目(位于名为C:\ ASP.NET Testing \ ASP.NET 4.0示例的文件夹中)。

我可以编译工程优良,运行默认页等

我试图从一本书(ASP.NET 4.0在实践)在一个简单的例子来加载。所以,我创建了一个子文件夹CH01,然后复制到.aspx和.aspx.vb文件中。

当我调试,我得到

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Could not load type 'ASP.NET_4._0.Global_asax'. 

Source Error: 

Line 1: <%@ Application Codebehind="Global.asax.vb" Inherits="ASP.NET_4._0.Global_asax" Language="vb" %> 

在浏览器窗口。

的示例代码(已经从网站上下载)是:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="1-4.aspx.vb" Inherits="_1_4" %> 
<html> 
<head> 
<title>Listing 1.4</title> 
</head> 
<body> 
    <form id="Form1" runat="server"> 
     <div> 
      <asp:literal id="ResponseText" runat="server" /> 
      <br /> 
      Enter your name: 
      <asp:textbox runat="server" ID="Name" /> 
      <br /> 
      <asp:button runat="server" Text="Click Me" ID="ClickButton" OnClick="HandleSubmit" /> 
     </div> 
    </form> 
</body> 
</html> 

Partial Class _1_4 
    Inherits System.Web.UI.Page 

    Sub HandleSubmit(ByVal sender As Object, ByVal e As EventArgs) 
     ResponseText.Text = "Your name is: " & Name.Text 
    End Sub 

End Class 

在VS,我也得到一个错误的信息,凸显了ResponseText.Text =“您名字是:“& Name.Text

'ResponseText' is not declared. It may be inaccessible due to its protection level. 

Global.asxa文件

Imports System.Web.SessionState 

Public Class Global_asax 
    Inherits System.Web.HttpApplication 

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) 
     ' Fires when the application is started 
    End Sub 

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) 
     ' Fires when the session is started 
    End Sub 

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) 
     ' Fires at the beginning of each request 
    End Sub 

    Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs) 
     ' Fires upon attempting to authenticate the use 
    End Sub 

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) 
     ' Fires when an error occurs 
    End Sub 

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) 
     ' Fires when the session ends 
    End Sub 

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) 
     ' Fires when the application ends 
    End Sub 

End Class 

我很明显错过了一些非常简单的东西,但我不明白。我看不到任何需要在VS中设置的任何说明。

谢谢。

如果我从VS添加,此页面可以正常工作。实际上,我从示例中复制了相同的页面,但对页面标记进行了轻微更改。它有一个由VS自动生成的.designer.vb页面。

14.aspx 
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="14.aspx.vb" Inherits="ASP.NET_4._0._14" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html> 
<head> 
<title>Listing 1.4</title> 
</head> 
<body> 
    <form id="Form1" runat="server"> 
     <div> 
      <asp:literal id="ResponseText" runat="server" /> 
      <br /> 
      Enter your name: 
      <asp:textbox runat="server" ID="Name" /> 
      <br /> 
      <asp:button runat="server" Text="Click Me" ID="ClickButton" OnClick="HandleSubmit" /> 
     </div> 
    </form> 
</body> 
</html> 

14.aspx.vb 
Public Class _14                     
    Inherits System.Web.UI.Page                 

    Sub HandleSubmit(ByVal sender As Object, ByVal e As EventArgs)        
     ResponseText.Text = "Your name is: " & Name.Text           
    End Sub                      

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    End Sub                      

End Class 

14.aspx.designer.vb 
'------------------------------------------------------------------------------                       
' <auto-generated>                
'  This code was generated by a tool.           
'                     
'  Changes to this file may cause incorrect behavior and will be lost if  
'  the code is regenerated.             
' </auto-generated>                
'------------------------------------------------------------------------------ 

Option Strict On                 
Option Explicit On                


Partial Public Class _14               

    '''<summary>                 
    '''Form1 control.                
    '''</summary>                 
    '''<remarks>                 
    '''Auto-generated field.              
    '''To modify move field declaration from designer file to code-behind file. 
    '''</remarks>                 
    Protected WithEvents Form1 As Global.System.Web.UI.HtmlControls.HtmlForm  

    '''<summary>                 
    '''ResponseText control.              
    '''</summary>                 
    '''<remarks>                 
    '''Auto-generated field.              
    '''To modify move field declaration from designer file to code-behind file. 
    '''</remarks>                 
    Protected WithEvents ResponseText As Global.System.Web.UI.WebControls.Literal 

    '''<summary>                 
    '''Name control.                
    '''</summary>                 
    '''<remarks>                 
    '''Auto-generated field.              
    '''To modify move field declaration from designer file to code-behind file. 
    '''</remarks>                 
    Protected WithEvents Name As Global.System.Web.UI.WebControls.TextBox   

    '''<summary>                 
    '''ClickButton control.              
    '''</summary>                 
    '''<remarks>                 
    '''Auto-generated field.              
    '''To modify move field declaration from designer file to code-behind file. 
    '''</remarks>                 
    Protected WithEvents ClickButton As Global.System.Web.UI.WebControls.Button 
End Class                   

回答

0

在您的网站的根目录上检查global.asax。类名/名称空间似乎有问题。我认为这与您添加的文件没有任何关系,而是与您可能错误移动或删除的内容有关。

+0

我没有碰过global.asax文件。如果我删除添加的文件,一切工作正常。我想知道这是否与继承声明有关? – Keith 2014-08-27 19:36:09

+0

只是看看它。 .net无法找到类名称。 global.asax中的类名是什么? – Ted 2014-08-27 19:37:17

+0

我已将global.asxa内容添加到帖子中。 – Keith 2014-08-27 19:39:59