Scenario: I have made a custom control, that works quite well. Basically a tab control, easy enough.
It comprises of 2 child controls which are derived from MultiView and View. So i have GBMMultiView and GBMView. The reason is there are a couple of extra properties added to each for our application needs.
GBMTab is the control that handles bringing things together, and GBMTab is the one developers would use in the designer.
The control seems to show up in the designer only as an empty squar and renders thee following when the control is dragged from toolbar to page:
<gbm:gbmtabs
id="GBMTabs1"
runat="server"></gbm:gbmtabs>
Then Intellisense would provide me the initial <tabs> tag, and in that I can create GBMviews. The page works and renders to a browser fine. My problems are all in the designer.
1) The tag should render the <tabs ></tabs> automaticlly along with the <gbm:gbmtabs
id="GBMTabs1"
runat="server"></gbm:gbmtabs> so that i could just drag
a gbmview onto the section without having to type that in first.
2) When I drag the GBMview (inheriged from view) onto the control, it works, but i get an error saying views can only be added to multiview controls. GBMTab contains a GBMMultiView as you recall and GBMMultiView inherits from
MultiView, so it should work... but I probaly have to fix the designer for something.
Now.... GBMTab also has a asp:menu in it, that I dont really care if it renders, so I wont even ask about that for now.
By goal is to make it so I can drag GBMtab onto page, and in designer it would like like a multiview designer, that would let me drag gbmviews onto it.
I am attaching a bit of code here, mainly jsut to make it clear what the objects are... and more or less how I was trying to design them. This is really my first endever into designer stuff... and to be honest most the documentation
/ guides i find online about this are alittle convulated ( if anyone knows a particularly good guide, please let me know ).
In any case... any help / directions / guidance with how to achive what I am trying to do would be great. Thanks.
My current status is as folowos code wise1,
[Designer(typeof(GBM.Framework.Web.UI.Controls.GBMTabsDesigner))]
[ToolboxData("<{0}:GBMTabs runat=server></{0}:GBMTabs>")]
[ParseChildren(true)]
[AspNetHostingPermission(SecurityAction.Demand, Level =
AspNetHostingPermissionLevel.Minimal)]
public class
GBMTabs : Panel, INamingContainer
{
private GBMMultiView _multiview =
null;
private Menu _tabs =
null;
.....
protected override
void CreateChildControls()
{
if (this.ChildControlsCreated)
return;
_tabs = new
Menu();
if (this.SkinID.Length == 0)
_tabs.SkinID = this.defaultSkinID;
else
_tabs.SkinID = this.SkinID;
_tabs.MenuItemClick += new
MenuEventHandler(TabMenu_ItemClick);
_multiview = new GBMMultiView();
_multiview.SkinID = this.SkinID;
this.Controls.Add(_tabs);
HtmlGenericControl tabCanvas =
new HtmlGenericControl("div");
tabCanvas.Attributes.Add("class",
"TabCanvas");
if (this.Width !=
Unit.Empty)
tabCanvas.Attributes.CssStyle.Add("width",
this.Width.ToString());
if (this.Height !=
Unit.Empty)
tabCanvas.Attributes.CssStyle.Add("height",
this.Height.ToString());
jminond
Contributor
2898 Points
608 Posts
ControlDesigner - Derived Controls - a little long with code samples.
May 18, 2006 03:15 PM|LINK
Hello.
Scenario: I have made a custom control, that works quite well. Basically a tab control, easy enough.
It comprises of 2 child controls which are derived from MultiView and View. So i have GBMMultiView and GBMView. The reason is there are a couple of extra properties added to each for our application needs.
GBMTab is the control that handles bringing things together, and GBMTab is the one developers would use in the designer.
The control seems to show up in the designer only as an empty squar and renders thee following when the control is dragged from toolbar to page:
<gbm:gbmtabs id="GBMTabs1" runat="server"></gbm:gbmtabs>
Then Intellisense would provide me the initial <tabs> tag, and in that I can create GBMviews. The page works and renders to a browser fine. My problems are all in the designer.
1) The tag should render the <tabs ></tabs> automaticlly along with the <gbm:gbmtabs id="GBMTabs1" runat="server"></gbm:gbmtabs> so that i could just drag a gbmview onto the section without having to type that in first.
2) When I drag the GBMview (inheriged from view) onto the control, it works, but i get an error saying views can only be added to multiview controls. GBMTab contains a GBMMultiView as you recall and GBMMultiView inherits from MultiView, so it should work... but I probaly have to fix the designer for something.
Now.... GBMTab also has a asp:menu in it, that I dont really care if it renders, so I wont even ask about that for now.
By goal is to make it so I can drag GBMtab onto page, and in designer it would like like a multiview designer, that would let me drag gbmviews onto it.
I am attaching a bit of code here, mainly jsut to make it clear what the objects are... and more or less how I was trying to design them. This is really my first endever into designer stuff... and to be honest most the documentation / guides i find online about this are alittle convulated ( if anyone knows a particularly good guide, please let me know ).
In any case... any help / directions / guidance with how to achive what I am trying to do would be great. Thanks.
My current status is as folowos code wise1,
[Designer(typeof(GBM.Framework.Web.UI.Controls.GBMTabsDesigner))]
[ToolboxData("<{0}:GBMTabs runat=server></{0}:GBMTabs>")]
[ParseChildren(true)]
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public class GBMTabs : Panel, INamingContainer
{
private GBMMultiView _multiview = null;
private Menu _tabs = null;
.....
protected override void CreateChildControls()
{
if (this.ChildControlsCreated)
return;
_tabs = new Menu();
if (this.SkinID.Length == 0)
_tabs.SkinID = this.defaultSkinID;
else
_tabs.SkinID = this.SkinID;
_tabs.MenuItemClick += new MenuEventHandler(TabMenu_ItemClick);
_multiview = new GBMMultiView();
_multiview.SkinID = this.SkinID;
this.Controls.Add(_tabs);
HtmlGenericControl tabCanvas = new HtmlGenericControl("div");
tabCanvas.Attributes.Add("class", "TabCanvas");
if (this.Width != Unit.Empty)
tabCanvas.Attributes.CssStyle.Add("width", this.Width.ToString());
if (this.Height != Unit.Empty)
tabCanvas.Attributes.CssStyle.Add("height", this.Height.ToString());
tabCanvas.Controls.Add(_multiview);
this.Controls.Add(_multiview);
this.Controls.Add(tabCanvas);
base.CreateChildControls();
this.ChildControlsCreated = true;
}
....
}
( Note the next class is where I have no clue how to acheive my desired results.....
public
class GBMTabsDesigner : ControlDesigner{
private GBMTabs designTimeGBMTabs;
public
override void Initialize(IComponent component){
base.Initialize(component);
designTimeGBMTabs = (GBMTabs)component;
designTimeGBMTabs.GetDesignTimeHtml();
}
public override string GetDesignTimeHtml()
{
try
{
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
string baseHTML = base.GetDesignTimeHtml();
Table table = new Table();
table.ApplyStyle(designTimeGBMTabs.ControlStyle);
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.Controls.Add(designTimeGBMTabs.TabDynMenu);
tr.Cells.Add(tc);
table.Rows.Add(tr);
tr = new TableRow();
tc = new TableCell();
//designTimeGBMTabs.TabDynMenu.RenderControl(htw);
tc.Controls.Add(designTimeGBMTabs.Tabs);
tr.Cells.Add(tc);
table.Rows.Add(tr);
table.RenderControl(htw);
return sw.ToString();
}
catch (Exception ex)
{
throw new Exception("Error in GBMTabsDesigner.GetDesignTimeHtml: " + ex.ToString());
}
}
[ToolboxData("<{0}:GBMMultiView runat=server></{0}:GBMMultiView>"), DefaultProperty("")]
//[Designer(typeof(GBM.Framework.Web.UI.Controls.GBMMultiViewDesigner))]
[Designer(typeof(MultiViewDesigner))]
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public class GBMMultiView : MultiView, INamingContainer
[ToolboxData("<{0}:GBMView runat=server></{0}:GBMView>"), DefaultProperty("Title")]
//[Designer(typeof(GBM.Framework.Web.UI.Controls.GBMViewDesigner))]
[Designer(typeof(ViewDesigner))]
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public class GBMView : View, INamingContainer {
http://www.Jonavi.com
http://www.jonavi.com/Default.aspx?pageID=21
http://RainbowBeta.com
http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/default.aspx
http://dotnetslackers.com/community/blogs/jminond/default.aspx