加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 自定义控件变为通用的“UserControl”,而不是其在Des

发布时间:2020-12-15 18:58:49 所属栏目:asp.Net 来源:网络整理
导读:我在ASP.NET中有一个自定义控件(VB.NET代码),用ASCX定义: %@ Control Language="vb" AutoEventWireup="false" CodeBehind="MyControl.ascx.vb" Inherits="Mynamespace.Controls.MyControl" %!-- some html and other custom controls-- 并在代码背后: Name
我在ASP.NET中有一个自定义控件(VB.NET代码),用ASCX定义:
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="MyControl.ascx.vb" Inherits="Mynamespace.Controls.MyControl" %>

<!-- some html and other custom controls-->

并在代码背后:

Namespace Controls

    Public Class MyControl
        Inherits System.Web.UI.UserControl

这是在图书馆中设置的.不同的项目在页面中使用该控件:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="mypage.aspx.vb" 
    Inherits="myproject.mypage" culture="auto" meta:resourcekey="Page" uiculture="auto" 
    Transaction="RequiresNew" MasterPageFile="Mynamespace.Master" 
    Theme="ThemeBase2" StylesheetTheme="ThemeBase2" %>

<%@ Register tagprefix="Controls" tagname="MyControl" src="../Controls/MyControl.ascx" %>

<%-- some asp.net --%>

<Controls:MyControl ID="mycontrol1" runat="server" 
                    MyCustomProperty="value" />

但是,当我建立,我得到一个错误说

‘MyCustomProperty’ is not a member of ‘System.Web.UI.UserControl’.

而在designer.vb页面中我看到:

Protected WithEvents mycontrol1 As Global.System.Web.UI.UserControl

如何确保它成为:

Protected WithEvents mycontrol1 As Global.Mynamespace.Controls.MyControl

解决方法

您的ascx文件无法访问,因为它在库中

您需要将ascx文件保存为库的嵌入式资源,并将其作为外部资源加载到Web应用程序中.

您可以咨询此link了解更多信息.

如果你想分享你的控件,我建议创建UserControl而不是CustomControl.不幸的是,有更多的工作,因为设计师是不可用的

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读