Hey guys, I´ve got a custom server control and it works like I want it to, However, in design view, it won´t work.
I´ve got the following IDesigner:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.Resources;
namespace CustomTools
{
class CustomButtonDesigner: ControlDesigner
{
public override string GetDesignTimeHtml()
{
string designTimeHtml = null;
designTimeHtml = "<div style=\"width:120px;height:40px;background-color: gray;color: white; font-weight: bold;text-align: center; border:2px solid white;\">"+ this.ID.ToString() +"</div>";
return designTimeHtml;
}
public override void Initialize(IComponent component)
{
if (!(component is Control) && !(component is INamingContainer))
{
throw new ArgumentException("component must be a container control");
}
base.Initialize(component);
}
}
}
AS you can see, I am simply loading a Div with a background color adn the name of the control. Nothing special.
When I load te control in DesignView, if it´s by itself it loads properly, however, if I place it inside an ASP table or a Placeholder, it will give me the following error in design view it will make these not render in design view (again, it all works as expected on runtime)
For example, I´ve got one instance of my control by itself, and below it, I have a Table with an instance of my control inside.
On DesignTime, the CustomButton1 control, which is by itself, will render properly, while the CustomButton2, which is inside the table, will throw this error:
Error Rendering Control - Table1
An unhandled exception has ocurred.
Object reference not set to an instance of an object.
If I then place the CustomButton2 in a Placeholder, I will get:
Error Rendering Control - PlaceHolder1
An unhandled exception has ocurred.
Object reference not set to an instance of an object.
Any Ideas as to what may be causing this? How can i work around it?
Pizana
Member
56 Points
71 Posts
Help with DesignerView and Custom Control
Feb 15, 2012 03:11 PM|LINK
Hey guys, I´ve got a custom server control and it works like I want it to, However, in design view, it won´t work.
I´ve got the following IDesigner:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; using System.ComponentModel.Design; using System.Web.UI; using System.Web.UI.Design; using System.Web.UI.WebControls; using System.Resources; namespace CustomTools { class CustomButtonDesigner: ControlDesigner { public override string GetDesignTimeHtml() { string designTimeHtml = null; designTimeHtml = "<div style=\"width:120px;height:40px;background-color: gray;color: white; font-weight: bold;text-align: center; border:2px solid white;\">"+ this.ID.ToString() +"</div>"; return designTimeHtml; } public override void Initialize(IComponent component) { if (!(component is Control) && !(component is INamingContainer)) { throw new ArgumentException("component must be a container control"); } base.Initialize(component); } } }AS you can see, I am simply loading a Div with a background color adn the name of the control. Nothing special.
When I load te control in DesignView, if it´s by itself it loads properly, however, if I place it inside an ASP table or a Placeholder, it will give me the following error in design view it will make these not render in design view (again, it all works as expected on runtime)
For example, I´ve got one instance of my control by itself, and below it, I have a Table with an instance of my control inside.
as shown:
<cc1:RDCButton ID="CustomButton1" runat="server" ButtonText="asdf" ControlLock="False" alarmString="0000000000" CssClass="buttonClass" Height="40px" Width="120px"></cc1:RDCButton> <br /> <br /> <asp:Table ID="Table1" runat="server"> <asp:TableRow runat="server"> <asp:TableCell runat="server"> <cc1:RDCButton ID="CustomButton2" runat="server" ButtonText="asdf" ControlLock="False" alarmString="0000000000" CssClass="buttonClass" Height="40px" Width="120px"></cc1:RDCButton> </asp:TableCell> </asp:TableRow> </asp:Table>On DesignTime, the CustomButton1 control, which is by itself, will render properly, while the CustomButton2, which is inside the table, will throw this error:
Error Rendering Control - Table1
An unhandled exception has ocurred.
Object reference not set to an instance of an object.
If I then place the CustomButton2 in a Placeholder, I will get:
Error Rendering Control - PlaceHolder1
An unhandled exception has ocurred.
Object reference not set to an instance of an object.
Any Ideas as to what may be causing this? How can i work around it?
All help is appreciated!
customcontrol error rendering control