首页 > 解决方案 > 从带有命名空间的 ASPX 页面引用代码隐藏函数

问题描述

我有一个非常不寻常的问题,希望得到帮助。我在 VS 2019 中有一个 Web 应用程序。

我正在尝试创建一个在其自己的命名空间中运行的页面,以便我可以与其他网站共享它。下面是一个简单的示例页面和代码。

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="test1.aspx.vb" Inherits="xxxx.test1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <%= Myfunc1() %> 
        </div>
    </form>
</body>
</html>

Namespace xxxx
    Public Class test1
        Inherits System.Web.UI.Page
        Public Function Myfunc1() As String
            Myfunc1 = "Hello"
        End Function
    End Class
End Namespace

编译显示 <%= Myfunc1() %> 为 MyFunc1 not found。

如果我从后面的代码中删除“命名空间 xxxx”并将 Inherits="xxxx.test1" 更改为 Inherits "TestWebsite.test1"(TestWebsite 是 Web 项目的命名空间,也是添加测试页时的默认设置)。此代码编译并正常工作。

对于如何实现使页面的名称空间独立于网站项目的目标,我将不胜感激。

谢谢保罗

标签: asp.netnamespaces

解决方案


推荐阅读