本文整理匯總了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);
}
}