Unable to call App_Code class from a code-behind(无法从代码隐藏调用 App_Code 类)
问题描述
我在App_Code"文件夹中的文件中有一个类.我可以在aspx"文件中使用它,但不能从代码隐藏文件中使用.如何使其对代码隐藏可见?
I have a class in a file that's in the "App_Code" folder. I'm able to use this in an "aspx" file but not from a code-behind file. How do I make it visible to a code-behind?
注意:这是 Mono 上的 ASP.Net,我直接编写类,而不是使用 IDE 编译它们
我的文件:
<%@ Page language="c#" src="TestAppCode.aspx.cs" Inherits="TestAppCode.TestAppCode" AutoEventWireup="true" %>
<html>
<head>
<title>Test App_Code Folder</title>
</head>
<body>
<form id="contactForm" runat="server">
<asp:TextBox id="Name" runat="server" ></asp:TextBox>
<asp:TextBox id="Age" runat="server" ></asp:TextBox>
<asp:Button ID="Submit" runat="server" Text="Submit" onclick="SubmitForm" />
</form>
</body>
<html>
代码隐藏 (TestAppCode.aspx.cs)
using System;
using System.Web.UI.WebControls;
namespace TestAppCode
{
public class TestAppCode : System.Web.UI.Page
{
protected void SubmitForm(object sender, EventArgs e)
{
//It fails here with the error: CS0246: The type or namespace name
//`MyAppCodeClass' could not be found. Are you missing a using
//directive or an assembly reference?
MyAppCodeClass m = new MyAppCodeClass();
}
}
}
APP_CODE CLASS (App_Code/MyAppCodeClass.cs)
public class MyAppCodeClass
{
public MyAppCodeClass() {}
}
我尝试给它一个命名空间,但这并不能解决问题.
I tried giving it a namespace, but that doesn't fix the issue.
推荐答案
将你的类的 Build Action 更改为 Compile.
Change your class' Build Action to Compile.
这篇关于无法从代码隐藏调用 App_Code 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法从代码隐藏调用 App_Code 类
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
