Custom Controls and User Controls
2005-08-06 05:52
453 查看
Custom Controls and User Controls both have sense of "customized" control. There is a bit of confusing, isn't it? Well, myself have developed a couple of user controls for my projects. I did quite frequently referring them as Custom
Controls..which is wrong. Those are actual User Controls.
Custom Controls are deriving from either System.Web.UI.Control or System.Web.UI.WebControls.WebControl. (Webcontrols have additional UI properites). They are customized by overriding the Control's Render method with HtmlTextWriter. User Controls are basically .ascx files.
A simple Custom Control:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyCustomControl
To use this custom control in your page, you need to register it with Register directive before you can use it.
<%@ Register TagPrefix="MyControl" Namespace="MyCustomControl" Assembly="MyCustomControl" %>
<html>
<body>
<form runat="server">
Most introductory applications output:
<MyControl:MyCustomControl runat="server" />
</form>
</body>
</html>
User Controls are quite frequently some header and footer files. e.g. footer.ascx
<%@ Control Language="VB" %>
<p align="left">
<font size="1">© 2004, AAA Inc.
<br />
Comments and suggestions, please forward to ME</font>
</p>
You can drag the footer.ascx directly into your page, while Visual Studio will take care of the registration and implementation. e.g.
<%@ Page language="c#" %>
<%@ Register TagPrefix="uc0" TagName="Footer" Src="Footer.ascx" %>
<html>
<body>
<form runat="server">
<uc0:Footer id="UserControl1" runat="server"></uc0:Footer>
</form>
</body>
</html>
It worths to metion that, a User Control with VB.NET can be used in C# pages.
Not only header and footer are common User Controls, but any .aspx page can be converted to a User Control by changing
<%@ Page Language="VB" %>
into
<%@ Control Language="VB" %>
Just write this article to clear some concepts in my mind on the road to prepare 30-315 exam. Hope helps someone.
Controls..which is wrong. Those are actual User Controls.
Custom Controls are deriving from either System.Web.UI.Control or System.Web.UI.WebControls.WebControl. (Webcontrols have additional UI properites). They are customized by overriding the Control's Render method with HtmlTextWriter. User Controls are basically .ascx files.
A simple Custom Control:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyCustomControl
To use this custom control in your page, you need to register it with Register directive before you can use it.
<%@ Register TagPrefix="MyControl" Namespace="MyCustomControl" Assembly="MyCustomControl" %>
<html>
<body>
<form runat="server">
Most introductory applications output:
<MyControl:MyCustomControl runat="server" />
</form>
</body>
</html>
User Controls are quite frequently some header and footer files. e.g. footer.ascx
<%@ Control Language="VB" %>
<p align="left">
<font size="1">© 2004, AAA Inc.
<br />
Comments and suggestions, please forward to ME</font>
</p>
You can drag the footer.ascx directly into your page, while Visual Studio will take care of the registration and implementation. e.g.
<%@ Page language="c#" %>
<%@ Register TagPrefix="uc0" TagName="Footer" Src="Footer.ascx" %>
<html>
<body>
<form runat="server">
<uc0:Footer id="UserControl1" runat="server"></uc0:Footer>
</form>
</body>
</html>
It worths to metion that, a User Control with VB.NET can be used in C# pages.
Not only header and footer are common User Controls, but any .aspx page can be converted to a User Control by changing
<%@ Page Language="VB" %>
into
<%@ Control Language="VB" %>
Just write this article to clear some concepts in my mind on the road to prepare 30-315 exam. Hope helps someone.
相关文章推荐
- 40、XAML user and custom controls
- Custom Controls and User Controls
- User controls and custom controls
- ASP.NET User Controls and Custom Server Controls
- Embedding and retrieving resources in custom controls
- WinForms Controls > Examples > How to: Add New XtraForm, RibbonForm and XtraUserControl to Your Proj
- Pro .NET 2.0 Windows Forms and Custom Controls in C#
- Developing SharePoint WebParts using User Controls and Web Applications
- Windows Controls and WPF UserControls inside an XNA Game Project
- Building a WPF Sudoku Game: Part 4 - Building a Least Privilege Plug-in System and Even More Custom Controls (zz)
- Creating and Using custom controlsin VC++
- Q&A: What's the difference between CustomControl and UserControl?
- 对 Web user controls 和 Web custom controls 的一些建议
- Web user controls 和 Web custom controls
- Professional Web Parts and Custom Controls with ASP.NET 2.0
- Packaging ASP.NET User Controls into an Assembly and Reuse it Multiple Projects
- Building a WPF Sudoku Game: Part 4 - Building a Least Privilege Plug-in System and Even More Custom Controls
- 学习custom control and usercontrol
- [web referrence] Sequence that events are raised for Pages, UserControls, MasterPages and HttpModules
- Core - Provide an easy way to store administrator and user model differences in a custom store (e.g., in a database)