Web Control Designing Questions
-
I had write a WebControl and its designer.The following is som of my code
[Designer("SM.WebControls.PagingControlDesigner"), ParseChildren(false)] public class PagingControl : System.Web.UI.WebControls.WebControl,INamingContainer { [Bindable(true), EditorAttribute(typeof(UrlEditor), typeof(UITypeEditor))] public string FirstButtonImg { get{return Convert.ToString(ViewState["FirstButtonImg"]);} set{ViewState["FirstButtonImg"] = value;} } protected PlaceHolder ParsedSubObjectContainer = new PlaceHolder(); protected override void CreateChildControls() { Panel Panel1 = new Panel(); Create some Controls and add to Panel1 Controls.Add(Panel1); Controls.Add(ParsedSubObjectContainer); } protected override void AddParsedSubObject(Object obj) { ParsedSubObjectContainer.Controls.Add((Control)obj); } internal string GetDesignTimeHtml() { EnsureChildControls(); StringWriter sw = new StringWriter(); HtmlTextWriter writer = new HtmlTextWriter(sw); this.RenderControl(writer); return sw.ToString(); } ... } public class PagingControlDesigner : ControlDesigner { public override bool DesignTimeHtmlRequiresLoadComplete { get{ return true;} } private PagingControl PagingControlInstance; public override void Initialize(System.ComponentModel.IComponent component) { this.PagingControlInstance = (PagingControl) component; base.Initialize (component); } public override string GetDesignTimeHtml() { return PagingControlInstance.GetDesignTimeHtml(); } ... }
I faced two problems when I writing this WebControl. The First is when I try to bind the FirstButtonImg property in a web form, the expression is not evaluated.It simple pass the '<%= Expression %>' string to the property<SM:PagingControl id="PagingControl1" runat="server" FirstButtonImg='<%= Expression %>' >
I do call PagingControl1.DataBind() in my WebForm's code. The second, when I am designing a WebFrom:<SM:PagingControl id="PagingControl1" runat="server"> <asp:DataGrid id="DataGrid1" runat="server"> </asp:DataGrid> </SM:Pa