继承自 page/usercontrol 中定义的代码块 class

Inherit from code-block defined class in page/usercontrol

TL;DR

是否可以使用代码块中定义的 class 替换 UserControlInherits="...",而不是编译代码中的 class-落后?


我有一个 ASP.NET 网络应用程序,我需要快速修补,但我只能更新 .aspx.ascx 文件...这是不可能的我重新编译并发布 .dll 文件(由于客户对我们提出的变更管理流程)。

在应用程序中,我有一个 UserControl 从文件的代码隐藏 class 中设置为 Inherit...但是其中有一个错误 class.

我想做的是在 .ascx 文件的 <script runat="server"></script> 块中重新创建整个 class,并修复相应的错误。

我尝试了以下方法,但我得到...

Could not load type 'MyCtrlStatic'.

<%@ Control Language="vb" AutoEventWireup="false" Inherits="MyCtrlStatic" %>
<script runat="server">
  Public Class MyCtrlStatic
    Inherits UserControl
    Public Function DisplayValue() As String
      Return "Hello World"
    End Function
  End Class
</script>
<div><%=DisplayValue()%></div>

有问题的控件使用了很多来自代码隐藏 class 的不同属性和方法,上面是对问题的大量简化。

这可以实现吗?否则我正在考虑重建并完成整个变更管理程序。

答案就在眼前,直到几分钟前我才看到...

与其尝试声明一个新的 Class 并从中继承,答案是直接从 UserControl 继承,然后将代码直接放在代码块中。

<%@ Control Language="vb" AutoEventWireup="false" Inherits="UserControl" %>
<script runat="server">
  Public Function DisplayValue() As String
    Return "Hello World"
  End Function
</script>
<div><%=DisplayValue()%></div>

除了上面的,我还得加几个Import命令,比如...

<%@ Import Namespace="System.Collections.Generic" %>

但现在我有一个修补的 .ascx 文件,不需要重建 DLL 就可以工作