I'm running into strange problems all around after converting my .NET 1.1 code in VC# 2003 to .NET 2.0 in VC# 2005.
I have a custom control based off of WebControl. The tag is defined as "cc:CustomControl", since this control rendered as an HTC component on the client end. I have a custom designer based on ControlDesigner now (didn't work without it either) that simply
outputs an HTML table.
This control does not behave like other controls that are built the same way and I can't figure out why. When I try to click on this control on a web form it doesn't select like other controls. When I try to grab this control and move it to a different
spot, the whole web form behaves like a drop target as if I were trying to move the control into a region, and keeps it at the top left corner. At the bottom left of the IDE, the status bar displays "Left: auto Top: auto". Other controls that move fine display
"Left: ###px Top ###px" as they should. I don't know why or how to regulate that.
Does anyone have an idea of what I'm doing wrong? This control worked fine in VC# 2003.
Why not to use (just Drag&Drop from ToolBox) ready Menu or TreeView?
I do not quite understand your logic drawing on Design surface without support or link to any Run- or Design-time properties
Even if you want to invent biecycle reimplementing what already exists. Yoг can compose (e.g. Composite or DropDownList, etc.) custom control at design-time and draw it symply by
public class CompositeControlDesigner : ControlDesigner {
public override string GetDesignTimeHtml() {
// Retrieve the controls to ensure they are created.
ControlCollection controls = ((Control)Component).Controls;
return base.GetDesignTimeHtml();
}
public override void Initialize(IComponent component) {
if (!(component is Control) &&
!(component is INamingContainer)) {
throw new ArgumentException(
"Component must be a container control.",
"component");
}
base.Initialize(component);
}
}
}
Gennady Vanin (Novosibirsk) -- Геннадий Ванин (Новосибирск) -- Guennadi Vanine
1) The sample I showed you is just an example. I wrote it specifically to illustrate the problem I'm having. It is not my actual code. It is just an example of the problem I'm experiencing. The control does nothing on purpose, to show the problem with
the designer, it's not meant to be executed at runtime.
2) Yes, I'm sure there's a better option, but I don't have that luxury unfortunately. I work at a company that is upgrading our existing code from .Net 1.1 to 2.0, with as little rewritting as possible.
3) You mention that the designer code has problems. What problems? Everything looks ok to me. It doesn't need to access anything in the control as far as I know, it's simply meant to be a non-functional representation of the control.
Given the sample code I provided, why can I not move it around in the designer? Why does it stay at the top left and only allow me to drag it into containers? What am I missing. This worked in 1.1.
<div>Well, your ContextMenuTestDesigner doesn''t render ContextMenuTest control.
It does render content (and not even control) of another webcontrol (Table tbl) overwriting by it yout ContextMenuTest control</div> <div>This rendering is not related (or even persisted) into
ContextMenuTest custom control in any way
My advise is to form your custom control in order to render and not vice versa (to render it in order to form) </div> <div> </div>
Gennady Vanin (Novosibirsk) -- Геннадий Ванин (Новосибирск) -- Guennadi Vanine
Forget what I wrote after BTW.
You should have run-time HTML generated in ContextMenuTest class and as final step the same mimicked in GetDesignTimeHtml () and not vice versa
Gennady Vanin (Novosibirsk) -- Геннадий Ванин (Новосибирск) -- Guennadi Vanine
Thanks for your responses, but I don't believe your assumptions are correct. You can render absolutely anything you want from GetDesignTimeHtml, and you don't have to render a single thing from the actual control, since the designer overrides it and we're
not actually rendering the control at runtime.
I have determined that the problem is actually related to WebControl.AddAttributesToRender.
This method seems to add css positioning information to the control's main tag that allows it to move around in the designer. However, I don't know where it's getting those values from. ControlStyle is empty. Attributes is empty. There's something tricky
going on in this function.
Phlow
0 Points
7 Posts
Custom control can't be moved from the top left corner in the designer. (.NET 2.0 VC#2005)
Dec 20, 2006 11:37 PM|LINK
I'm running into strange problems all around after converting my .NET 1.1 code in VC# 2003 to .NET 2.0 in VC# 2005.
I have a custom control based off of WebControl. The tag is defined as "cc:CustomControl", since this control rendered as an HTC component on the client end. I have a custom designer based on ControlDesigner now (didn't work without it either) that simply outputs an HTML table.
This control does not behave like other controls that are built the same way and I can't figure out why. When I try to click on this control on a web form it doesn't select like other controls. When I try to grab this control and move it to a different spot, the whole web form behaves like a drop target as if I were trying to move the control into a region, and keeps it at the top left corner. At the bottom left of the IDE, the status bar displays "Left: auto Top: auto". Other controls that move fine display "Left: ###px Top ###px" as they should. I don't know why or how to regulate that.
Does anyone have an idea of what I'm doing wrong? This control worked fine in VC# 2003.
ControlDesigner "design-time" web control server control control asp.net 2.0
Phlow
0 Points
7 Posts
Re: Custom control can't be moved from the top left corner in the designer. (.NET 2.0 VC#2005)
Dec 21, 2006 11:18 PM|LINK
public class ContextMenuTestDesigner : System.Web.UI.Design.ControlDesigner { public ContextMenuTestDesigner( ) { } public override bool AllowResize { get { return false; } } public override string GetDesignTimeHtml( ) { Table tbl = new Table( ); tbl.CellPadding = 1; tbl.CellSpacing = 1; tbl.Style.Add( HtmlTextWriterStyle.BackgroundColor, "menu" ); tbl.Style.Add( HtmlTextWriterStyle.BorderCollapse, "collapse" ); tbl.Style.Add( HtmlTextWriterStyle.BorderStyle, "outset" ); tbl.Style.Add( HtmlTextWriterStyle.BorderWidth, "2px" ); tbl.Style.Add( HtmlTextWriterStyle.Display, "block" ); tbl.Style.Add( HtmlTextWriterStyle.FontSize, "8pt" ); tbl.Style.Add( HtmlTextWriterStyle.FontFamily, "Microsoft Sans Serif, Verdana, Arial, Helvetica" ); tbl.Style.Add( HtmlTextWriterStyle.Padding, "1px" ); for( int i = 1; i <= 10; i++ ) { TableRow tr = new TableRow( ); TableCell td = new TableCell( ); if( (i % 3) != 0 ) // 2 items, then a separator { WebControl wc = new WebControl( HtmlTextWriterTag.Div ); if( i == 2 ) // hilight 2nd item { wc.Style.Add( HtmlTextWriterStyle.BackgroundColor, "highlight" ); wc.Style.Add( HtmlTextWriterStyle.Color, "highlighttext" ); } else { // alternate disabled look wc.Style.Add( HtmlTextWriterStyle.Color, ((i % 2) != 0) ? "black" : "inactivecaptiontext" ); } wc.Style.Add( HtmlTextWriterStyle.Cursor, "default" ); wc.Style.Add( HtmlTextWriterStyle.Overflow, "visible" ); wc.Style.Add( HtmlTextWriterStyle.Padding, "2px 18px 2px 14px" ); wc.Style.Add( HtmlTextWriterStyle.Width, "100%" ); LiteralControl lc = new LiteralControl( ); lc.Text = "Menu Item " + i.ToString( ); wc.Controls.Add( lc ); td.Controls.Add( wc ); } else { td.Height = Unit.Pixel( 0 ); td.Style.Add( "border-top", "1px solid threedshadow" ); td.Style.Add( "border-bottom", "1px solid threedhighlight" ); } tr.Cells.Add( td ); tbl.Rows.Add( tr ); } StringWriter sw = new StringWriter( ); HtmlTextWriter htw = new HtmlTextWriter( sw ); tbl.RenderControl( htw ); return sw.ToString( ); } } [ Designer( typeof( ContextMenuTestDesigner ) ), ToolboxData( "<{0}:ContextMenuTest runat=\"server\"></{0}:ContextMenuTest>" ) ] public class ContextMenuTest : System.Web.UI.WebControls.WebControl { public ContextMenuTest( ) : this( String.Empty ) { } public ContextMenuTest( string id ) : base( HtmlTextWriterTag.Div ) // base( "c:ContextMenuTest" ) { this.ID = id; } }Phlow
0 Points
7 Posts
Re: Custom control can't be moved from the top left corner in the designer. (.NET 2.0 VC#2005)
Dec 21, 2006 11:21 PM|LINK
The attributes for ContextMenuTest got escaped by the forum software, should be:
[
Designer( typeof( ContextMenuTestDesigner ) ),
ToolboxData( "<{0}:ContextMenuTest runat=\"server\"></{0}:ContextMenuTest>" )
]
guenavan
Contributor
4306 Points
1695 Posts
Re: Custom control can't be moved from the top left corner in the designer. (.NET 2.0 VC#2005)
Dec 22, 2006 09:01 AM|LINK
Delete
Designer(typeof(ContextMenuTestDesigner)),
before
public class ContextMenuTest : System.Web.UI.WebControls.WebControl
{
and everything works OK
guenavan
Contributor
4306 Points
1695 Posts
Re: Custom control can't be moved from the top left corner in the designer. (.NET 2.0 VC#2005)
Dec 22, 2006 11:16 AM|LINK
I do not quite understand your logic drawing on Design surface without support or link to any Run- or Design-time properties
Even if you want to invent biecycle reimplementing what already exists. Yoг can compose (e.g. Composite or DropDownList, etc.) custom control at design-time and draw it symply by
public class CompositeControlDesigner : ControlDesigner {
public override string GetDesignTimeHtml() {
// Retrieve the controls to ensure they are created.
ControlCollection controls = ((Control)Component).Controls;
return base.GetDesignTimeHtml();
}
public override void Initialize(IComponent component) {
if (!(component is Control) &&
!(component is INamingContainer)) {
throw new ArgumentException(
"Component must be a container control.",
"component");
}
base.Initialize(component);
}
}
}
Phlow
0 Points
7 Posts
Re: Custom control can't be moved from the top left corner in the designer. (.NET 2.0 VC#2005)
Dec 23, 2006 03:44 AM|LINK
Thanks for your reply.
1) The sample I showed you is just an example. I wrote it specifically to illustrate the problem I'm having. It is not my actual code. It is just an example of the problem I'm experiencing. The control does nothing on purpose, to show the problem with the designer, it's not meant to be executed at runtime.
2) Yes, I'm sure there's a better option, but I don't have that luxury unfortunately. I work at a company that is upgrading our existing code from .Net 1.1 to 2.0, with as little rewritting as possible.
3) You mention that the designer code has problems. What problems? Everything looks ok to me. It doesn't need to access anything in the control as far as I know, it's simply meant to be a non-functional representation of the control.
Given the sample code I provided, why can I not move it around in the designer? Why does it stay at the top left and only allow me to drag it into containers? What am I missing. This worked in 1.1.
Thanks
guenavan
Contributor
4306 Points
1695 Posts
Re: Custom control can't be moved from the top left corner in the designer. (.NET 2.0 VC#2005)
Dec 23, 2006 01:40 PM|LINK
It does render content (and not even control) of another webcontrol (Table tbl) overwriting by it yout ContextMenuTest control</div> <div>This rendering is not related (or even persisted) into ContextMenuTest custom control in any way
My advise is to form your custom control in order to render and not vice versa (to render it in order to form) </div> <div> </div>
guenavan
Contributor
4306 Points
1695 Posts
Re: Custom control can't be moved from the top left corner in the designer. (.NET 2.0 VC#2005)
Dec 25, 2006 02:53 AM|LINK
GetDesignTimeHtml method should return the HTML generated by the control at run time by calling the control's RenderControl method.
Once againg, check the snippet I provided above!
BTW Try to Right Click ---> Add New Item-->Component ---> Web Custom Control
The following class is created
namespace ClassLibrary1
{
partial class CountControls
{
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
Where is it (Required method for Designer support )?
guenavan
Contributor
4306 Points
1695 Posts
Re: Custom control can't be moved from the top left corner in the designer. (.NET 2.0 VC#2005)
Dec 25, 2006 06:57 AM|LINK
Forget what I wrote after BTW.
You should have run-time HTML generated in ContextMenuTest class and as final step the same mimicked in GetDesignTimeHtml () and not vice versa
Phlow
0 Points
7 Posts
Re: Custom control can't be moved from the top left corner in the designer. (.NET 2.0 VC#2005)
Jan 03, 2007 12:12 AM|LINK
Thanks for your responses, but I don't believe your assumptions are correct. You can render absolutely anything you want from GetDesignTimeHtml, and you don't have to render a single thing from the actual control, since the designer overrides it and we're not actually rendering the control at runtime.
I have determined that the problem is actually related to WebControl.AddAttributesToRender.
This method seems to add css positioning information to the control's main tag that allows it to move around in the designer. However, I don't know where it's getting those values from. ControlStyle is empty. Attributes is empty. There's something tricky going on in this function.
GetDesignTimeHtml AddAttributesToRender designer positioning