【问题标题】:Return a UserControl from a method that is not in the Code-Behind file.从不在代码隐藏文件中的方法返回 UserControl。
【发布时间】:2012-06-27 06:48:46
【问题描述】:

我想创建一个可以从不同的代码隐藏文件中调用的辅助方法。此方法将返回一个 UserControl (myUC)。但是,除了在 ASPX 文件或 web.config 文件中注册 UserControl 之外,我看不到任何访问 myUC 的方法,但这些方法都不会让我访问非代码隐藏 CS 文件。我想也许我可以将 UserControl 包装在命名空间中,然后在 CS 文件中使用该命名空间,但这也不起作用。

我正在考虑放弃将 UserControl 用于复合控件 (http://msdn.microsoft.com/en-us/library/aa719734(v=vs.71).aspx),因为它可以包装在命名空间中并用于任何 CS 文件。

但在我这样做之前,我想知道是否有人可以对此有所了解?

谢谢。 约瑟夫

【问题讨论】:

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


    【解决方案1】:

    UserControl 并不意味着从后面的代码中创建。这不是它的目的。您必须为此使用 CustomControl。在这里阅读:

    ASP.Net Custom controls vs. user controls: Are these two the same

    【讨论】:

      猜你喜欢
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      • 2015-01-26
      • 1970-01-01
      • 1970-01-01
      • 2013-10-17
      • 1970-01-01
      • 2015-12-30
      相关资源
      最近更新 更多