下面构建一个完全生成的基础控件,该控件需要从System.Web.UI.Control类派生,并且需要指定所有呈现到浏览器的HTML内容,呈现的内容是在该控件类中重写Render方法指定。
}

把上面代码文件添加到App_Code文件夹中,因为这个文件夹中的代码都将被动态编译。

通过HtmlTextWriter的Write方法,可以将指定内容输出到浏览器上。

下面代码展示了如何在页面中使用上面生成的新控件。


    <title>Show Fully Rendered Control</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    
    
<custom:FullyRenderedControl
        
ID="FullyRenderedControl1"
        Text2
="Hello World!" 
        runat
="Server" />
    
    
</div>
    
</form>
</body>
</html>

 

上面代码注册自定义控件是在页面中进行,也可以在Web配置文件的<Pages>节中为整个网站注册该控件。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-27
  • 2021-10-02
  • 2021-12-13
  • 2021-08-30
猜你喜欢
  • 2021-12-30
  • 2021-07-22
  • 2021-07-14
  • 2021-10-19
  • 2022-02-25
  • 2021-06-12
  • 2021-11-30
相关资源
相似解决方案