locked
Design Time Bug? Not Allowing Control To Be Resized RRS feed

  • Question

  • User7632503 posted

    I am developing a Web Server Control.  I am ding this in C# for ASP.Net 4.0.

    It is simply a splitter bar with two panels.  PanelA is the Top of Left panel depending on the orientation and PanelB is the Bottom or Right panel depending on the orientation. 

    I ran into what I think is a bug in Visual Studio.  At Design time, my control became unsizable when it previously was.  I tracked this down as happening when I applied the "Position: relative" attribute to the container Div.  When I apply the attribute, the control is not resizable at design time; when I don't apply the attribute, the control is sizable at design time.

    I was able to reproduce the behaviour in this widdled down version.  I think this is a bug in VS?  Or am missing some logic? 

    Example code is below 

    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace APR.Web.CustomControls.Research
    {
        [ToolboxData("<{0}:resizablewebcontrol runat="server">")]
        [Designer(typeof(ResizableWebControlDesigner))]
        public class ResizableWebControl : WebControl
        {
            #region Protected Properties
            /// <summary> /// Changes the root tag element to the type which is returned. /// </summary>
            protected override HtmlTextWriterTag TagKey
            {
                get
                {
                    return HtmlTextWriterTag.Div;
                }
            }
            #endregion
        }
    }
    
    using System.IO;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.Design;
    using System.Web.UI.HtmlControls;
    using System.Security.Permissions;
    
    namespace APR.Web.CustomControls.Research
    {
        [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
        public class ResizableWebControlDesigner : ControlDesigner
        {
            #region Public Methods
            public override bool AllowResize
            {
                get
                {
                    return true;
                }
            }
    
            public override string GetDesignTimeHtml()
            {
                ResizableWebControl rszControl = (ResizableWebControl)this.ViewControl;
    
                HtmlGenericControl RootContainer = new HtmlGenericControl("div");
                RootContainer.Style.Add(HtmlTextWriterStyle.Position, "relative");
                RootContainer.Style.Add(HtmlTextWriterStyle.BorderCollapse, "collapse");
                RootContainer.Style.Add(HtmlTextWriterStyle.BorderColor, "Black");
                RootContainer.Style.Add(HtmlTextWriterStyle.BorderStyle, "solid");
                RootContainer.Style.Add(HtmlTextWriterStyle.BorderWidth, "1px");
                RootContainer.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#DBD9DA");
                RootContainer.Style.Add(HtmlTextWriterStyle.Height, rszControl.Height.ToString());
                RootContainer.Style.Add(HtmlTextWriterStyle.Width, rszControl.Width.ToString());
    
    
                StringBuilder sb = new StringBuilder();
                StringWriter tw = new StringWriter(sb);
                HtmlTextWriter hw = new HtmlTextWriter(tw);
    
                RootContainer.RenderControl(hw);
                string s = sb.ToString();
    
                return s;
            }
            #endregion
        }
    }
    

    Any help is appreciated.

    Wednesday, December 21, 2011 4:22 PM

All replies