MIS2000 Lab. -- ASP.NET学习&分享 / ASP.NET案例精编(清华大学出版社)
您好,我来自台湾。很高兴与各位分享一些成果。希望对您有帮助。出版书籍是「ASP.NET案例精编 / 清华大学出版社」。

使用者自订控件 / User Control

http://www.dotblogs.com.tw/mis2000lab/archive/2008/05/14/3983.aspx

 

 

 

 

 

透过User Control可以取代以前ASP用的 「#include file =」,而且更灵活好用。

用法与ASP.NET 1.X差不多~

 

1. User Control 的扩展名,务必为 .ascx。 


2. 只要是重复使用的程序代码、或是组件、控件,都可以写在 User Control里面,在「主程序的画面」上(附档名 .aspx)重复使用。

 

3. 而且User Control 的引用,务必写在主程序(扩展名 .aspx)的<form runat="server">......</form >里面


4. UserControl 就连控件的tag名称(如下图的<Acme:Address),都可以自己命名喔!

 

以下是某一只主程序(附文件名 .aspx),引用 User Control 的作法----

<%@ Register TagPrefix="Acme" TagName="Address" Src="userctrl3_vb.ascx" %>

<html>
    <script language="VB" runat="server">
     省略.....
    </script>

<body style="font:10pt verdana">
  <h3>A Simple User Control w/ Properties</h3>

  <formrunat="server">
       <Acme:Address id="ShipAddr" Caption="Shipping Address" Address="One Microsoft Way"City="Redmond" StateName="WA" Zip="98052" runat="server"/> 

       <p>
      <Acme:Address id="BillAddr" Caption="Billing Address" runat="server"/> 

      <p>
       <asp:button Text="Submit Form" OnClick="SubmitBtn_Click"runat=server/>
  </form>

  <asp:Label id="MyLabel" runat="server"/>

</body>
</html>


也可以透过 Property的方式,用 Get 或是 Set (详见:微软官方文件)来作更多变化......,这部份,中文计算机书很少提到,请您一定要看看。

不愧是微软官方的在线说明文件,没话讲,写得很棒......甚至比市面上的中文计算机书都讲得好。
(这份文件也能在.NetFramework 2.0 SDK里面找到,安装后,可在自己硬盘上阅读,约400多MB的容量。 .NETframework 2.0 SDK中文说明文件(到微软官方网站下载))

 

 

 

 

 

 

 

更详细内容,书本里面有~ 本范例收录在本书的「11.3节」
ASP.NET案例精编(清华大学出版社)
请看:http://cht.gotdotnet.com/quickstart/aspplus/doc/webpagelets.aspx

 

 

 

posted on 2010-10-18 17:42  MIS2000 Lab.  阅读(271)  评论(0)    收藏  举报


ASP.NET案例精编——适用于VS 2005/2008(配光盘)
 

当当网购买 http://product.dangdang.com/product.aspx?product_id=20583373&ref=search-1-pub