【问题标题】:Parser Error in Namespace?命名空间中的解析器错误?
【发布时间】:2014-02-04 23:29:23
【问题描述】:

我有一个使用 All In One 样式(页面中带有 HTML 的 VB)构建的网页,我被要求将它们分开。

Default.aspx 是这样开始的:

<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="System.Security" %>
<html>
<head>
  <title>View an Activity (AFE)</title>
  <script language="VB" runat="server">

    Private m_url1, m_url2, m_downloadText, txtSupplementPage, txtExcerpt, SearchLocation, SearchLocation2, SearchLocation3, SearchLocationOrig As String
    Private myTotal1, myTotal2 As Double
    Private m_credentials As CredentialCache

    ' Start the initial page
    Protected Sub Page_Load(sender As Object, e As EventArgs)
      m_credentials = New CredentialCache()
      If Not IsPostBack Then

继续。这只是为了向您展示我在做什么。

我创建了一个名为 Default2.aspx 的新的类似文件,其中包含 Page 指令、指定 CodeBehind 文件和命名空间(继承)。然后我把VB代码拿出来了:

<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="app2._Default" %>

<!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 runat="server">
    <title>View an Activity (AFE)</title>

由于 Default.aspx 没有使用代码隐藏文件,我将新的代码隐藏文件命名为 Default.aspx.vb

我在此代码隐藏文件中创建了一个带有命名空间 app2 的新 _Default,并将所有 VB 从 Default.aspx 复制到它:

Namespace app2

  Public Class _Default

    Inherits System.Web.UI.Page
    Inherits System.Net
    Inherits System.IO
    Inherits System.Configuration
    Inherits System.Data
    Inherits System.Data.OleDb
    Inherits System.Data.SqlClient
    Inherits System.Globalization
    Inherits System.Security

    Private m_url1, m_url2, m_downloadText, txtSupplementPage, txtExcerpt, SearchLocation, SearchLocation2, SearchLocation3, SearchLocationOrig As String
    Private myTotal1, myTotal2 As Double
    Private m_credentials As CredentialCache

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      m_credentials = New CredentialCache()
      If Not IsPostBack Then

我试图提供足够多的代码,让每个人都能看到起点和我现在的位置。

我将两个新文件上传到网络服务器,然后浏览它们以查看它们的外观。

但是,现在当我尝试在浏览器中显示 Default2.aspx 时,我得到了这个 Parser Error

解析器错误消息:无法加载类型“app2._Default”。

来源错误:

第 1 行:
第 2 行:
第 3 行:

我搞砸了什么?

【问题讨论】:

    标签: asp.net .net vb.net


    【解决方案1】:

    对于网站:将 CodeBehind 更改为 CodeFile。

     <%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="app2._Default" %>
    

    对于 Web 应用程序:将 Web 项目的名称添加到 Inherits 属性。

     <%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="nameOfYourWebProject.app2._Default" %>
    

    另外,您提供的 _Default 类,您只能有一个 Inherits,我想您的意思是将它们作为 Imports 添加到页面顶部。

    【讨论】:

    • 代码在工作,现在是星期六。我会尽快检查。我真的很感谢你的帮助。你的眼睛很好。
    猜你喜欢
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2016-07-08
    相关资源
    最近更新 更多