本文整理汇总了C#中System.Web.UI.Design.ControlDesigner.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# ControlDesigner.Initialize方法的具体用法?C# ControlDesigner.Initialize怎么用?C# ControlDesigner.Initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.Design.ControlDesigner
的用法示例。
在下文中一共展示了ControlDesigner.Initialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefaultProperty
//引入命名空间
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
namespace AspNet.Samples
{
// Create a custom class to render the Text property
[Designer(typeof(SimpleDesigner)), DefaultProperty("Text"),
ToolboxData("<{0}:Simple runat=\"server\"></{0}:Simple>")]
public sealed class Simple : WebControl
{
public Simple()
{ }
// Create a Text property
[Browsable(true), Bindable(true),
PersistenceMode(PersistenceMode.Attribute)]
public string Text
{
get
{
object o = ViewState["TextProp"];
return (o == null) ? "Sample Text" : (string)o;
}
set { ViewState["TextProp"] = value; }
}
// Render the text inside the control
protected override void RenderContents(HtmlTextWriter writer)
{
writer.Write(Text);
}
}
}
namespace AspNet.Samples
{
//Create a designer class for the Simple control
public sealed class SimpleDesigner : ControlDesigner
{
// Declare a reference to the Simple class
private Simple simpleControl;
public SimpleDesigner()
{ }
public override void Initialize(IComponent ponent)
{
base.Initialize(ponent);
// Get a reference to the control
simpleControl = (Simple)ponent;
//Set Text to the control's ID
simpleControl.Text = simpleControl.ID;
}
// Allow resizing the control in the design host
public override bool AllowResize
{
get
{
return true;
}
}
public override string GetDesignTimeHtml()
{
if (simpleControl.Text.Length > 0)
{
string spec = "<a href='{0}.aspx'>{0}</a>";
return String.Format(spec, simpleControl.Text);
}
else
{
return GetEmptyDesignTimeHtml();
}
}
}
}