C# 实现IPostbackHandler.net
我有一个从占位符继承的服务器控件C# 实现IPostbackHandler.net,c#,.net,asp.net,C#,.net,Asp.net,我有一个从占位符继承的服务器控件 基本上,它只是一个占位符,顶部有一个“,看起来您只需要一个可以包含其他控件或“模板”的服务器控件,我刚刚使用以下示例完成了此操作: 这应该可以处理回发上完成的所有工作 根据上述链接改编的基本示例: 使用制度; 使用系统组件模型; 使用System.Security.Permissions; 使用System.Web; 使用System.Web.UI; 使用System.Web.UI.Design; 使用System.Web.UI.WebControl 命名空间M
基本上,它只是一个占位符,顶部有一个
“,看起来您只需要一个可以包含其他控件或“模板”的服务器控件,我刚刚使用以下示例完成了此操作:
这应该可以处理回发上完成的所有工作
根据上述链接改编的基本示例:
使用制度;
使用系统组件模型;
使用System.Security.Permissions;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.Design;
使用System.Web.UI.WebControl
命名空间Made4Print.Web.UI
{
[AspNetHostingPermission(SecurityAction.InheritanceDemand,Level=AspNetHostingPermissionLevel.Minimal),AspNetHostingPermissionLevel(SecurityAction.Demand,Level=AspNetHostingPermissionLevel.Minimal),Designer(typeof(VacationHomeDesigner)),DefaultProperty(“标题”),ToolboxData(“”,]
公共类TemplateContainer:CompositeControl
{
私有ITemplate模板值;
私有模板所有者ownerValue
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public TemplateOwner Owner
{
get
{
return ownerValue;
}
}
[Browsable(false), PersistenceMode(PersistenceMode.InnerProperty), DefaultValue(typeof(ITemplate), ""), Description("Control template"), TemplateContainer(typeof(TemplateContainer))]
public virtual ITemplate Template
{
get
{
return templateValue;
}
set
{
templateValue = value;
}
}
protected override void CreateChildControls()
{
Controls.Clear();
ownerValue = new TemplateOwner();
ITemplate temp = templateValue;
if (temp == null)
{
temp = new DefaultTemplate();
}
temp.InstantiateIn(ownerValue);
this.Controls.Add(ownerValue);
}
public override void DataBind()
{
CreateChildControls();
ChildControlsCreated = true;
base.DataBind();
}
}
[ToolboxItem(false)]
public class TemplateOwner : WebControl
{
}
#region DefaultTemplate
sealed class DefaultTemplate : ITemplate
{
void ITemplate.InstantiateIn(Control owner)
{
// Create Controls Here
//Label title = new Label();
//title.DataBinding += new EventHandler(title_DataBinding);
//owner.Controls.Add(title);
}
//void title_DataBinding(object sender, EventArgs e)
//{
// Label source = (Label)sender;
// TemplateContainer container = (TemplateContainer)(source.NamingContainer);
// source.Text = container.Title;
//}
}
#endregion
public class VacationHomeDesigner : ControlDesigner
{
public override void Initialize(IComponent Component)
{
base.Initialize(Component);
SetViewFlags(ViewFlags.TemplateEditing, true);
}
public override string GetDesignTimeHtml()
{
return "<span>[Template Container Control]</span>";
}
public override TemplateGroupCollection TemplateGroups
{
get
{
TemplateGroupCollection collection = new TemplateGroupCollection();
TemplateGroup group;
TemplateDefinition template;
TemplateContainer control;
control = (TemplateContainer)Component;
group = new TemplateGroup("Item");
template = new TemplateDefinition(this, "Template", control, "Template", true);
group.AddTemplateDefinition(template);
collection.Add(group);
return collection;
}
}
}
[可浏览(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
公共模板所有者
{
得到
{
返回自己的价值;
}
}
[可浏览(false)、PersistenceMode(PersistenceMode.InnerProperty)、DefaultValue(typeof(ITemplate)、“”)、说明(“控制模板”)、TemplateContainer(typeof(TemplateContainer))]
公共虚拟项目板模板
{
得到
{
返回模板值;
}
设置
{
templateValue=值;
}
}
受保护的覆盖无效CreateChildControls()
{
控件。清除();
ownerValue=新模板所有者();
ITemplate temp=模板值;
if(temp==null)
{
temp=新的DefaultTemplate();
}
临时实例化EIN(ownerValue);
this.Controls.Add(ownerValue);
}
公共覆盖无效数据绑定()
{
CreateChildControls();
ChildControlsCreated=true;
base.DataBind();
}
}
[ToolboxItem(假)]
公共类TemplateOwner:WebControl
{
}
#区域默认模板
密封类默认模板:ITemplate
{
void ITemplate.ein(控件所有者)
{
//在此处创建控件
//标签标题=新标签();
//title.DataBinding+=新事件处理程序(title\u DataBinding);
//所有者。控件。添加(标题);
}
//无效标题\u数据绑定(对象发送方、事件参数e)
//{
//标签源=(标签)发送方;
//TemplateContainer=(TemplateContainer)(source.NamingContainer);
//source.Text=container.Title;
//}
}
#端区
公共类度假家居设计师:ControlDesigner
{
公共覆盖无效初始化(IComponent组件)
{
初始化(组件);
SetViewFlags(ViewFlags.TemplateEditing,true);
}
公共重写字符串GetDesignTimeHtml()
{
返回“[模板容器控件]”;
}
公共覆盖TemplateGroupCollection TemplateGroups
{
得到
{
TemplateGroupCollection集合=新建TemplateGroupCollection();
模板组;
模板定义模板;
模板容器控制;
控件=(TemplateContainer)组件;
组=新模板组(“项目”);
模板=新模板定义(此“模板”,控件,“模板”,true);
group.AddTemplateDefinition(模板);
集合。添加(组);
回收;
}
}
}
}看起来您只需要一个可以包含其他控件或“模板”的服务器控件,我刚刚使用以下示例完成了此操作:
这应该可以处理回发上完成的所有工作
根据上述链接改编的基本示例:
使用制度;
使用系统组件模型;
使用System.Security.Permissions;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.Design;
使用System.Web.UI.WebControl
命名空间Made4Print.Web.UI
{
[AspNetHostingPermission(SecurityAction.InheritanceDemand,Level=AspNetHostingPermissionLevel.Minimal),AspNetHostingPermissionLevel(SecurityAction.Demand,Level=AspNetHostingPermissionLevel.Minimal),Designer(typeof(VacationHomeDesigner)),DefaultProperty(“标题”),ToolboxData(“”,]
公共类TemplateContainer:CompositeControl
{
私有ITemplate模板值;
私有模板所有者ownerValue
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public TemplateOwner Owner
{
get
{
return ownerValue;
}
}
[Browsable(false), PersistenceMode(PersistenceMode.InnerProperty), DefaultValue(typeof(ITemplate), ""), Description("Control template"), TemplateContainer(typeof(TemplateContainer))]
public virtual ITemplate Template
{
get
{
return templateValue;
}
set
{
templateValue = value;
}
}
protected override void CreateChildControls()
{
Controls.Clear();
ownerValue = new TemplateOwner();
ITemplate temp = templateValue;
if (temp == null)
{
temp = new DefaultTemplate();
}
temp.InstantiateIn(ownerValue);
this.Controls.Add(ownerValue);
}
public override void DataBind()
{
CreateChildControls();
ChildControlsCreated = true;
base.DataBind();
}
}
[ToolboxItem(false)]
public class TemplateOwner : WebControl
{
}
#region DefaultTemplate
sealed class DefaultTemplate : ITemplate
{
void ITemplate.InstantiateIn(Control owner)
{
// Create Controls Here
//Label title = new Label();
//title.DataBinding += new EventHandler(title_DataBinding);
//owner.Controls.Add(title);
}
//void title_DataBinding(object sender, EventArgs e)
//{
// Label source = (Label)sender;
// TemplateContainer container = (TemplateContainer)(source.NamingContainer);
// source.Text = container.Title;
//}
}
#endregion
public class VacationHomeDesigner : ControlDesigner
{
public override void Initialize(IComponent Component)
{
base.Initialize(Component);
SetViewFlags(ViewFlags.TemplateEditing, true);
}
public override string GetDesignTimeHtml()
{
return "<span>[Template Container Control]</span>";
}
public override TemplateGroupCollection TemplateGroups
{
get
{
TemplateGroupCollection collection = new TemplateGroupCollection();
TemplateGroup group;
TemplateDefinition template;
TemplateContainer control;
control = (TemplateContainer)Component;
group = new TemplateGroup("Item");
template = new TemplateDefinition(this, "Template", control, "Template", true);
group.AddTemplateDefinition(template);
collection.Add(group);
return collection;
}
}
}
[可浏览(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
公共模板所有者
{
得到
{
返回自己的价值;
}
}
[可浏览(false)、PersistenceMode(PersistenceMode.InnerProperty)、DefaultValue(typeof(ITemplate)、“”)、说明(“控制模板”)、TemplateContainer(typeof(TemplateContainer))]
公共虚拟项目板模板
{
得到
{
返回模板值;
}
设置
{
templateValue=值;
}
}
受保护的覆盖无效CreateChildControls()
{
控件。清除();
ownerValue=新模板所有者();
ITemplate temp=模板值;
if(temp==null)
{
temp=新的DefaultTemplate();
}
临时实例化EIN(ownerValue);
this.Controls.Add(ownerValue);
}
公共覆盖无效数据绑定()
{
CreateChildControls();
ChildControlsCreated=true;
base.DataBind();
}
}
[ToolboxItem(假)]
公共类TemplateOwner:WebControl
{
}
#区域默认模板
密封类默认模板:ITemplate
{
void ITemplate.ein(控件所有者)
{
//在此处创建控件
//标签标题=新标签();
//title.DataBinding+=新事件处理程序(title\u DataBinding);