Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
namespace MessageBoxControl
{
    [DefaultProperty("Text")]
    [Category("Appearance")]

    [Description("This is the Custom Message Box")]
    [ToolboxData("<{0}:MessageBox  runat="server">")]
    public class MessageBox : CompositeControl
    {
        public string msgString = "";
        public string _msgType = "";
        public static string Error = "Error";
        public static string Warning = "Warning";
        public static string Success = "Success";
        public static string Info = "Info";
        Literal ltrmsg = new Literal();

         [DefaultValue("Custom MessageBox")]
        public string Message
        {
            get
            {
                EnsureChildControls();
                return ltrmsg.Text != null ? ltrmsg.Text : string.Empty;
            }
            set
            {
                EnsureChildControls();
                ltrmsg.Text = value;
            }
        }
        public string MessagegType
        {
            get
            {
                return _msgType;
            }
            set
            {
                _msgType = value;
            }
        }

        
        protected override void OnPreRender(EventArgs e)
        {
            HtmlGenericControl cssLink, cssLink2;
            cssLink = new HtmlGenericControl("link");
            cssLink2 = new HtmlGenericControl("link");
            cssLink.ID = "animation";
            cssLink.Attributes.Add("href", Page.ClientScript.GetWebResourceUrl(this.GetType(), "MessageBoxControl.animate.css"));
            cssLink.Attributes.Add("type", "text/css");
            cssLink.Attributes.Add("rel", "StyleSheet");

            cssLink2.ID = "MessageBox";
            cssLink2.Attributes.Add("href", Page.ClientScript.GetWebResourceUrl(this.GetType(), "MessageBoxControl.MessageBoxStyles.css"));
            cssLink2.Attributes.Add("type", "text/css");
            cssLink2.Attributes.Add("rel", "StyleSheet");
            Page.Header.Controls.Add(cssLink);
            Page.Header.Controls.Add(cssLink2);
            base.OnPreRender(e);
      
        }


        protected override void CreateChildControls()
        {
            Controls.Clear();
            ltrmsg.ID = "ltrmsgid";

            this.Controls.Add(ltrmsg);
            base.CreateChildControls();

        }
        protected override void OnInit(EventArgs e)
        {
            
            base.OnInit(e);
        }
        protected override void Render(HtmlTextWriter Writer)
        {
            try
            {
                string type = MessagegType.ToLower();
                switch (type)
                {
                    case "error":
                        Writer.AddAttribute(HtmlTextWriterAttribute.Class, "error");
                        break;
                    case "info":
                        Writer.AddAttribute(HtmlTextWriterAttribute.Class, "info");
                        break;
                    case "success":
                        Writer.AddAttribute(HtmlTextWriterAttribute.Class, "success");
                        break;
                    case "warning":
                        Writer.AddAttribute(HtmlTextWriterAttribute.Class, "warning");
                        break;
                    default:
                        Writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "#FFF");
                        Writer.AddStyleAttribute(HtmlTextWriterStyle.BorderColor, "#000");
                        break;
                }

                Writer.RenderBeginTag(HtmlTextWriterTag.Div);
                ltrmsg.RenderControl(Writer);
                Writer.RenderEndTag();

            }
            catch (Exception ex)
            {


            }
        }
    }
}

XML
I have create composite server control using above code. I have used the css files for this control.
But when I use this control on aspx page or on webform it doesn't give the css effect.
Why ?
Posted
Updated 19-Sep-15 0:43am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900