Inheriting a web control

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I have webcontrol from which I would like to inherit so I can encapsulate it
within a table and let users configure it a design time.
My table renders and the property editor contains the control from which I
inherited but when I try to make modifications to the control such as adding
properties that it handles, I receive errors. The control I'm using is a
third party control which does inherit from WebControl.

What do I minimally need to do in my inherited class to make this work?
 
Hi,

you should provide some code to demonstrate what you have done so far. There
shouldn't be anything too hard to get this to work, but that's all I can say
with this much information.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

I have webcontrol from which I would like to inherit so I can encapsulate it
within a table and let users configure it a design time.
My table renders and the property editor contains the control from which I
inherited but when I try to make modifications to the control such as adding
properties that it handles, I receive errors. The control I'm using is a
third party control which does inherit from WebControl.

What do I minimally need to do in my inherited class to make this work?
 
public class EDMenu : DevExpress.Web.Menus.MainMenu, INamingContainer
{
public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}
protected override void CreateChildControls()
{
Controls.Clear();
base.CreateChildControls();
this.ID = "EDMenu1";
this.Height = Unit.Pixel(21);
this.BorderWidth = Unit.Empty;
this.ImageToLeft = "";
this.ImageToRight = "images/nav/spacer2.gif";
this.Width = Unit.Percentage(100);
this.BackColor = ColorTranslator.FromHtml("#EAEAEA");
this.Font.Size = FontUnit.Point(10);
string[] arFontNames = new string[4];
arFontNames[0] = "verdana";
arFontNames[1] = "arial";
arFontNames[2] = "helvetica";
arFontNames[3] = "sans-serif";
this.Font.Names = arFontNames;
this.ForeColor = ColorTranslator.FromHtml("#666666");
this.Font.Bold = true;
this.Root.ItemHeight = Unit.Pixel(18);
this.SelectedItemStyle.Font.Size = FontUnit.Point(10);
this.SelectedItemStyle.Font.Names = arFontNames;
this.SelectedItemStyle.Font.Bold = true;
this.SelectedItemStyle.BorderWidth = Unit.Pixel(1);
this.SelectedItemStyle.ForeColor = Color.Black;
this.SelectedItemStyle.BorderColor = Color.Black;
this.SelectedItemStyle.BackColor = Color.LightGray;
this.SeparatorStyle.Height = Unit.Pixel(18);
this.SeparatorStyle.ForeColor = Color.Black;
this.SeparatorStyle.BorderColor = Color.Transparent;
this.SeparatorStyle.Width = Unit.Pixel(4);
this.MenuItems.Add(new DevExpress.Web.Menus.MenuItem());
Controls.Add(this);
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
writer.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Bgcolor, "#054ca6");
writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
writer.RenderBeginTag(HtmlTextWriterTag.Table);
RenderHeader(writer);
RenderMenu(writer);
RenderFooter(writer);
RenderShadow(writer);
writer.RenderEndTag();//table
}
protected void RenderMenu(HtmlTextWriter writer)
{
//<tr>
writer.RenderBeginTag(HtmlTextWriterTag.Tr);


//<td id="tdLeft" width="6" background="images/nav/left.gif"
height="18"><IMG src="images/nav/left.gif"></td>
writer.AddAttribute(HtmlTextWriterAttribute.Id, "tdLeft");
writer.AddAttribute(HtmlTextWriterAttribute.Width,"6");
writer.AddAttribute(HtmlTextWriterAttribute.Height,"18");

writer.AddAttribute(HtmlTextWriterAttribute.Background,"images/nav/left.gif"
);
writer.AddAttribute(HtmlTextWriterAttribute.Src,"images/nav/left.gif");
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.RenderEndTag();//td

//<td id="tdMenu" bgColor="#eaeaea" height="18" runat="server">
writer.AddAttribute(HtmlTextWriterAttribute.Id, "tdMenu");
writer.AddAttribute(HtmlTextWriterAttribute.Height,"18");
writer.AddAttribute(HtmlTextWriterAttribute.Bgcolor,"#eaeaea");
writer.AddAttribute(HtmlTextWriterAttribute.Valign,"Top");
writer.RenderBeginTag(HtmlTextWriterTag.Td);
base.RenderContents(writer);
writer.RenderEndTag();//td

//<td id="tdRight" width="6" background="images/nav/right.gif"
height="18"><IMG src="images/nav/right.gif"></td>
writer.AddAttribute(HtmlTextWriterAttribute.Id, "tdRight");
writer.AddAttribute(HtmlTextWriterAttribute.Width,"6");

writer.AddAttribute(HtmlTextWriterAttribute.Background,"images/nav/right.gif
");
writer.AddAttribute(HtmlTextWriterAttribute.Src,"images/nav/right.gif");
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.RenderEndTag();//td

writer.RenderEndTag();//tr

}

}
 
Back
Top