本文整理汇总了C#中System.Web.UI.TemplateControl类的典型用法代码示例。如果您正苦于以下问题:C# TemplateControl类的具体用法?C# TemplateControl怎么用?C# TemplateControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TemplateControl类属于System.Web.UI命名空间,在下文中一共展示了TemplateControl类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Construct
//引入命名空间
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;
// The custom user control class.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class MyControl : UserControl
{
// Create a Message property and accessors.
private string _message = "No message";
public string Message
{
get { return _message; }
set { _message = value; }
}
// Create an event for this user control
public event System.EventHandler myControl;
// Override the default constructor.
protected override void Construct()
{
// Specify the handler for the OnInit method.
this.myControl += new EventHandler(MyInit);
}
protected override void OnInit(EventArgs e)
{
myControl(this, e);
Response.Write("The OnInit() method is used to raise the Init event.");
}
// Use the MyInit handler to set the Message property
void MyInit(object sender, System.EventArgs e)
{
Message = "Hello World!";
}
// Render the value of the Message property
protected override void Render(HtmlTextWriter writer)
{
writer.Write("<br>Message :" + Message);
}
}