using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.Design; using System.Drawing; namespace ServerControl { public class CollapsiblePanelDesigner : ContainerControlDesigner { private Style _style = null; // Add the caption by default. Note that the caption // will only appear if the Web server control // allows child controls rather than properties. public override string FrameCaption { get { return "Collapsible Panel"; } } public override Style FrameStyle { get { if (_style == null) { _style = new Style(); _style.Font.Name = "Verdana"; _style.Font.Size = new FontUnit("XSmall"); _style.BackColor = Color.LightBlue; _style.ForeColor = Color.Black; } return _style; } } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ServerControl { [DefaultProperty("Text")] [ToolboxData("<{0}:CollapsiblePanel runat=server></{0}:CollapsiblePanel>")] [Designer(typeof(CollapsiblePanelDesigner))] [ParseChildren(false)] public class CollapsiblePanel : WebControl { [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] public string Text { get { String s = (String)ViewState["Text"]; return ((s == null) ? String.Empty : s); } set { ViewState["Text"] = value; } } protected override HtmlTextWriterTag TagKey { get { return HtmlTextWriterTag.Div; } } private string title = "标题"; private string ImgUrl_down = "Images/down.gif"; private string ImgUrl_up = "Images/up.gif"; [Description("向下图片路径")] public string ImgUrl_Up { get { return ImgUrl_up; } set { ImgUrl_up = value; } } [Description("向上图片路径")] public string ImgUrl_Down { get { return ImgUrl_down; } set { ImgUrl_down = value; } } public string Title { get { return title; } set { title = value; } } protected override void OnLoad(EventArgs e) { base.OnLoad(e); //注册JS string Div_Client_ID = this.ClientID; //string JS = " function testjs() { var id= document.getElementById(/"<%=this.ClientID%>/");}"; //string JS = " function DropDown_Up(img) { var id= document.getElementById(/"" + Div_Client_ID + "-divContent/") ;if(id.style.display==/"block/") {id.style.display=/"none/";img.src=/"" + ImgUrl_up + "/";} else {id.style.display=/"block/";img.src=/"" + ImgUrl_Down + "/"}}"; string JS = " function DropDown_Up(img) { var id= img.parentNode.parentNode.nextSibling ;if(id.style.display==/"block/") {id.style.display=/"none/";img.src=/"" + ImgUrl_Up + "/";} else {id.style.display=/"block/";img.src=/"" + ImgUrl_Down + "/"}}"; ClientScriptManager manager = this.Page.ClientScript; if (!manager.IsClientScriptBlockRegistered(this.GetType(), "CollapsiblePanel_JS")) { manager.RegisterClientScriptBlock(this.GetType(), "CollapsiblePanel_JS", JS,true); } } protected override void RenderContents(HtmlTextWriter output) { output.Write("<div style="/" mce_style="/""height:20px;width:100% ; background-color:#369 ;border:1px solid #369/"><span style="/" mce_style="/""float:right;/"><img src="/" mce_src="/""" + ImgUrl_down + "/" style="/" mce_style="/""cursor:pointer/" onclick=/"DropDown_Up(this);/"></span><span>" + Title + "</span></div>"); //标题 output.Write("<div id=/""+this.ClientID+"-divContent/" style="/" mce_style="/""height:100%;width:100% ;overflow:auto;border:1px solid #369 ;display:block;/" >");//内容 List<Control> newCollection = new List<Control>(); for (int x = 0; x < Controls.Count; x++) { Control c=Controls[x]; newCollection.Add(Controls[x]); } foreach (Control c in newCollection) Controls.Add(c); base.RenderContents(output); } public override void RenderEndTag(HtmlTextWriter writer) { writer.Write("</div>"); base.RenderEndTag(writer); } } }