Allows you to include a sub-control webcontrol between control labels.

Source: Internet
Author: User
Tags control label

I wrote about usercontrol before http://www.cnblogs.com/coolkiss/archive/2010/09/07/1820467.html.

But the manager said that usercontrol is not reusable, so he switched to webcontrol and encountered some problems during the change process.

The main problem is that the control label contains sub-controls or Asp.net page variables.

 

The function I want to implement is to include sub-controls between controls.

<CC: titleex runat = "server">

<Asp: literal id = "litstr" runat = "server"/>

</CC: titleex>

 

At the same time

<CC: titleex runat = "server">

<% = "Hi" %>

</CC: titleex>

 

It can also be used as follows:

<CC: titleex runat = "server">

<% Response. Write ("str"); %>

</CC: titleex>

 

   [ParseChildren(false), PersistChildren(true), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]    public class TitleEx : WebControl    {        public TitleEx()            : base(HtmlTextWriterTag.Div)        {        }        #region Attribute        [Bindable(true)]        [Category("Appearance")]        [DefaultValue("")]        [Localizable(true)]        public string CssStyle        {            get            {                String s = (String)ViewState["CssStyle"];                return ((s == null) ? String.Empty : s);            }            set            {                ViewState["CssStyle"] = value;            }        }        [Bindable(true)]        [Category("Appearance")]        [DefaultValue("")]        [Localizable(true)]        public string CloseFunction        {            get            {                String s = (String)ViewState["CloseFunction"];                return ((s == null) ? String.Empty : s);            }            set            {                ViewState["CloseFunction"] = value;            }        }        [Bindable(true)]        [Category("Appearance")]        [DefaultValue("")]        [Localizable(true)]        public string DemoUrl        {            get            {                String s = (String)ViewState["DemoUrl"];                return ((s == null) ? String.Empty : s);            }            set            {                ViewState["DemoUrl"] = value;            }        }        [Bindable(true)]        [Category("Appearance")]        [DefaultValue("")]        [Localizable(true)]        [PersistenceMode(PersistenceMode.InnerDefaultProperty)]        public string Text        {            get            {                String s = (String)ViewState["Text"];                return ((s == null) ? String.Empty : s);            }            set            {                if (this.HasControls())                {                    this.Controls.Clear();                }                ViewState["Text"] = value;            }        }        [Bindable(true)]        [Category("Appearance")]        [DefaultValue("")]        [Localizable(true)]        public string HelpUrl        {            get            {                String s = (String)ViewState["HelpUrl"];                return ((s == null) ? String.Empty : s);            }            set            {                ViewState["HelpUrl"] = value;            }        }        #endregion        protected override void AddAttributesToRender(HtmlTextWriter writer)        {            base.AddAttributesToRender(writer);            writer.AddAttribute(HtmlTextWriterAttribute.Id, "divtitle");            if (CssStyle != null)            {                string strStyle = CssStyle;                writer.AddAttribute(HtmlTextWriterAttribute.Style, strStyle);            }        }        public override void RenderBeginTag(HtmlTextWriter writer)        {            this.AddAttributesToRender(writer);            HtmlTextWriterTag tagKey = this.TagKey;            if (tagKey != HtmlTextWriterTag.Unknown)            {                writer.RenderBeginTag(tagKey);                writer.Write(GetOutputHtmlBegin());            }            else            {                writer.RenderBeginTag(this.TagName);            }        }        public override void RenderEndTag(HtmlTextWriter writer)        {            writer.Write(GetOutputHtmlEnd());            base.RenderEndTag(writer);        }        #region get output html        protected string GetOutputHtmlBegin()        {            StringBuilder sbHtml = new StringBuilder();            sbHtml.AppendLine("<table width='100%' cellpadding=0 cellspacing=0 border=0 class='EMRTitle'>");            sbHtml.AppendLine("<tr>");            sbHtml.AppendLine("<td width='10%' align='left' class='EMRTitle'></td>");            sbHtml.AppendLine("<td width='90%' align='left' class='EMRTitle'>");            return sbHtml.ToString();        }        protected string GetOutputHtmlEnd()        {            StringBuilder sbHtml = new StringBuilder();            sbHtml.Append("</td>");            sbHtml.AppendLine("<td width=80 align='right' valign='top' nowrap>");            if (!string.IsNullOrEmpty(DemoUrl) && DemoUrl.IndexOf("HTTP") == -1)            {                DemoUrl = "http://www.oooo.com/help/video/" + DemoUrl;            }            if (!string.IsNullOrEmpty(DemoUrl) && DemoUrl.Length > 0)                sbHtml.AppendLine("<a href=\"javascript:\" onclick=\"javascript:pop('" + DemoUrl + "','',750,750);\"></a>");            if (!string.IsNullOrEmpty(HelpUrl) && HelpUrl.Length > 0)                sbHtml.AppendLine("<a href=\"javascript:\" onclick=\"javascript:pop('" + HelpUrl + "','',750,750);\"></a>");            if (!string.IsNullOrEmpty(CloseFunction) && CloseFunction.Length > 0)            {                sbHtml.AppendLine("  <a href=\"javascript:" + CloseFunction + "\"></a>");            }            sbHtml.AppendLine("</td>");            sbHtml.AppendLine("</tr>");            sbHtml.AppendLine("</table>");            return sbHtml.ToString();        }        #endregion    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.