如何为ASP.net UserControl指定名称空间? [英] How to specify a namespace for an ASP.net UserControl?

查看:103
本文介绍了如何为ASP.net UserControl指定名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.net中有一个UserControl:

i have a UserControl in ASP.net:

GrobSelector.ascx.cs :

GrobSelector.ascx.cs:

...
public partial class GrobSelector : System.Web.UI.UserControl
{
   ...

我想将此类包装在命名空间中

i want to wrap this class in a namespace:

GrobSelector.ascx.cs :

GrobSelector.ascx.cs:

...
namespace GrobSelectorNamespace
{
   public partial class GrobSelector : System.Web.UI.UserControl
   {
      ...
   ...       
}

除了现在代码无法编译:

Except now code fails to compile:

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

请确保此代码文件中定义的类与"inherits"属性匹配,并且扩展了正确的基类(例如Page或UserControl).

Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

将ASP.net UserControl放入命名空间的正确方法是什么?

What's the correct way to put an ASP.net UserControl in a namespace?

前置代码文件包含:

GrobSelector.ascx :

GrobSelector.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="GrobSelector.ascx.cs" 
    Inherits="GrobSelector"  %>

奖金阅读

  • 将Web用户控件(ascx)放置在名称空间中?
  • asp.net用户控件中的命名空间
  • 获取ASP.net找不到的名称空间名称用户控制
  • Bonus Reading

    • Putting a Web User Control (ascx) in a namespace?
    • namespace in asp.net usercontrol
    • Getting namespace name not found for ASP.net user control
    • 推荐答案

      您收到的错误可以正确解释.

      The error you received explains it correctly.

      您应该更改"in-front"文件,以使Inherits属性考虑到控件类所在的名称空间:

      You should change your 'in-front' file such that the Inherits attribute takes into account the namespace in which the control class resides:

      <%@ Control Language="C#" AutoEventWireup="true" CodeFile="VacationSelector.ascx.cs" 
          Inherits="VacationSelectorNamespace.VacationSelector"  %>
      

      这篇关于如何为ASP.net UserControl指定名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆