【问题标题】:CodeFile OK, CodeBehind gives "not declared" errorCodeFile OK,CodeBehind 给出“未声明”错误
【发布时间】:2012-10-10 02:27:44
【问题描述】:

我有一个使用 CodeFile 的 asp 项目,但是当我将其更改为 CodeBehind 时,在 aspx 文件中无法识别 vb 函数,从而在 aspx 文件中给出“名称...未声明”错误。

为了使用 CodeBehind,除了将顶行中的 codefile 更改为 codebehind 之外,还有其他事情要做吗?

以下代码在 aspx 文件中收到错误“名称 'connex' 未声明”。

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="browse.aspx.vb" Inherits="_browse" %> <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head runat="server"> <title>Test</title> </head> 
<body> 
<form id="form1" runat="server">
<div>
<%
  Dim s As String = connex()  
  Response.Write(s)
%>
</div>
</form>
</body>
</html>

===================

Imports System
Imports System.Web

Partial Public Class _browse
Inherits System.Web.UI.Page

Function connex() As String
  Return "OK"
End Function

End Class

【问题讨论】:

  • 我相信Inherits="MyNameSpace._browse" 在您的应用程序具有根命名空间时是必需的,您可以在项目属性中找到它。我相信根命名空间默认为您的应用程序的原始名称。如果没有根命名空间,Inherits="_browse" 可能会起作用。使用 DNN 时,我删除了根命名空间,但我将其保留在所有其他项目中。

标签: asp.net code-behind


【解决方案1】:

检查你的

Inherits="_browse"

确保包含正确的命名空间。

Inherits="MyNameSpace._browse"

【讨论】:

  • 谢谢!这样做。我必须删除代码文件的命名空间,将其添加到代码隐藏中。
猜你喜欢
  • 2010-09-09
  • 2012-05-12
  • 2011-02-04
  • 1970-01-01
  • 2015-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多