首页 新闻 会员 周边 捐助

提问:asp.net控件设计时

0
悬赏园豆:15 [已关闭问题] 关闭于 2009-10-22 20:27

最近在看谭震林的道不远人  看设计时支持这一章节了   觉得文中的讲将内容从设计区域转换到aspx文件中的例子不是很好

我想做一个div   在设计区域输入文字后能加到div控件中  于是有了下面的代码

//控件

 

 public  class TheAddButoonDiv:WebControl
    {
        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Div;
            }
        }
        protected override void RenderContents(HtmlTextWriter writer)
        {
            RenderChildren(writer);
        }
    }

//设计器
    public class theAddDesigner :ControlDesigner
    {
                
              

        public override string GetDesignTimeHtml(DesignerRegionCollection regions)
        {
            TheAddButoonDiv div = Component as TheAddButoonDiv;

            StringBuilder stringbuilder = new StringBuilder();
            StringWriter writer = new StringWriter(stringbuilder);
            HtmlTextWriter html = new HtmlTextWriter(writer);
            regions.Add(new EditableDesignerRegion(this,"thediv"));

            div.ControlStyle.AddAttributesToRender(html);
            html.AddAttribute(DesignerRegion.DesignerRegionAttributeName, "0");
            html.RenderBeginTag(HtmlTextWriterTag.Div);
            html.RenderEndTag();

            return stringbuilder.ToString();
        }
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region)
        {
            IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));
            if (host != null)
            {
                return ControlPersister.PersistControl(Component as Control, host);
            }
            return string.Empty;
        }
        public override void SetEditableDesignerRegionContent(EditableDesignerRegion region, string content)
        {
            if (content == null)
            {
                return;
            }
            IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));
            if (content != null)
            {
                TheAddButoonDiv control = Component as TheAddButoonDiv;
                ViewControl = null;
                ViewControl =ControlParser.ParseControl(host, content);
            }
        }
        public override bool AllowResize
        {
            get
            {
                return true;
            }
        }
    }

 

 

不知道怎么的  老是在设计区域显示组件名称必须唯一 且不区分大小写    我想是geteditableDesignerRegionContent方法中出了问题   我想问一下怎么修改   我无法想象  如何从设计器中代替原来的控件

xmlsvg的主页 xmlsvg | 初学一级 | 园豆:185
提问于:2009-10-20 10:14
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册