博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How to: Create Instances of ASP.NET User Controls Programmatically
阅读量:7071 次
发布时间:2019-06-28

本文共 2063 字,大约阅读时间需要 6 分钟。

 

To create an instance of a user control programmatically

 
  1. In the user control, be sure that the  directive contains a ClassName attribute that assigns a class to the user control.

    The following example sets the ClassName attribute to strongly type a user control.

     
     
    <%@ Control className="MyUserControl" %>
  2. In the page where you want to work with the user control, create a reference to the user control with the  directive.

    When you create the user control programmatically, the strong type for your user control is available to the ASP.NET Web page only after you have created a reference to it. For example, the following code creates a reference to a user control created in the MyUserControl.ascx file.

     
     
    <%@ Reference Control="MyUserControl.ascx" %>
    NoteNote

    You use the  when you intend to load the control programmatically. You use the  directive when you add a user control to the page declaratively. For details, see .

  3. Create an instance variable for the user control, using the control's class name. The class will be part of the ASP namespace.

    For example, if you want to create an instance of the user control declared as class Spinner, you use syntax such as the following:

    VB
     
    Protected Spinner1 As ASP.Spinner

     

    C#
     
    Protected ASP.Spinner Spinner1;
  4. Create an instance of the user control in code by calling the  method.

  5. Assign property values as necessary, and then add the control to the  collection of a container on the page, such as a  control.

    NoteNote

    When you add controls to the  object using the  method, they are placed in the collection in the order they are processed. If you want to add a control to a specific position in the collection, use the  method and specify the index location where you want to store the control.

 
<%@ Page Language="C#" %><%@ Reference Control="~/Controls/Spinner.ascx" %>      Load User Control Programmatically  
 

reference:

 

转载于:https://www.cnblogs.com/joe-yang/archive/2012/04/28/2474836.html

你可能感兴趣的文章
linux CentOS7最小化安装环境静默安装Oracle11GR2数据库(安装依赖包)
查看>>
运维自动化工具Cobbler之—标准化
查看>>
编译linux-3.15.5时遇到的几个错误
查看>>
nginx启动,重启,关闭命令
查看>>
redhat5.8+pam+mysql+vsftp(提供软件包可以到 百度云盘下载 账号 pankuo1@sina.cn 密码pk492940446)...
查看>>
支持Flash转换可打印的PDF文件的PDF转换控件ActivePDF WebGrabber
查看>>
JavaScript的一些概念: typeof, null, 和 undefined
查看>>
PL/SQL连接64位Oracle数据库
查看>>
关于Dr.Com3.73多人上网的破解(一)
查看>>
关于ChainCore开源区块链的Signer数量,Quroum配置
查看>>
mysqldump 备份数据库
查看>>
开启Pix ASA 5520 snmp协议
查看>>
Redhat镜像下载
查看>>
《数据结构与算法分析——c语言描述》读后笔记 7
查看>>
CheungSSH国产自动化运维工具开源Web界面
查看>>
mysql主从复制
查看>>
Lync Server部署之监控服务器部署
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
rsync + inotify 实现数据实时同步
查看>>