c# - 如何将 UserControl.ascx 的代码隐藏类放入另一个库中

标签 c# asp.net user-controls code-behind ascx

我有一个 UserControl.ascx 并希望此 ascx 使用(引用)另一个库(项目) 中的代码隐藏。所以在 @control 指令中,我执行以下操作

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="..\CodeBehinds\ucBehind1.cs" %> 

但是当运行页面时我看到了错误

Parser Error Message: Cannot use a leading .. to exit above the top directory.

有什么办法可以实现吗?

GitHub example Project

最佳答案

在您的示例中,删除继承自 UserControl1.ascx

在 usercontrol1.ascx.cs 中,取消注释所有代码。

改变

public partial class UserControl1 : System.Web.UI.UserControl

public partial class UserControl1 : otherClassInAnotherProject

otherClassInAnotherProject 最终应该继承自 System.Web.UI.UserControl

关于c# - 如何将 UserControl.ascx 的代码隐藏类放入另一个库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13139043/

相关文章:

c# - 如何从数组创建字典

c# - 当类型从同一接口(interface)派生时合并可观察序列

asp.net - Azure 应用服务应用程序设置无法通过 ConfigurationManager 获得

c# - 使用 AdoNetAppender 刷新 Log4Net 缓冲区

c# - wpf中的UserControl显示顺序

c# - EmguCV/OpenCV 中的 body 识别(跟踪视频中的人物)

c# - SQL连接字符串和cant参数visual studio 2013

asp.net - 读取已在 ASP.NET httpmodule 中设置的经典 ASP 中的服务器变量

c# - ScintillaNET 未显示方法 block 的折叠

c# - C#中用户控件的属性总是为false?