I want to create a basic webpart class(it should have the the controls like textbox and label created in this .cs file which inherits from webpart). in my aspx page i create a webpart manager and a webpart zone. Now i want to use this webpart i created in 2 aspx pages to demonstrate the reusability of webparts
here is my code
namespace PartsControl
{
public class AddrPart : WebPart
{
public AddrPart()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls();
_divPanel.ID = "_divPanel";
_divPanel.BorderStyle = BorderStyle.Ridge;
_divPanel.Width = 250;
_divPanel.Height = 300;
_divPanel.BackColor = System.Drawing.Color.Gainsboro;
Controls.Add(_divPanel);
}
protected override void OnPreRender(EventArgs e)
{
}
protected override void Render(HtmlTextWriter writer)
{
base.RenderControl(writer);
writer.Write(" <div id='_divPanel'>");
writer.Write(" <table style='border-right: 1px ridge; border-top: 1px ridge; border-left: 1px ridge;");
writer.Write(" border-bottom: 1px ridge; background-color: gainsboro;' cellpadding='3' cellspacing='2'");
writer.Write(" width='250'>");
if (_sErrDescription == "")
{
// dropdownlist State
writer.Write(" <tr style='border-right: 1px ridge; border-top: 1px ridge; border-left: 1px ridge;");
writer.Write(" border-bottom: 1px ridge;'>");
writer.Write(" <td style='height: 50px'>");
_ddlCountry.RenderControl(writer);
writer.Write(" </td>");
writer.Write(" </tr>");
}
}
aspx page:
<body>
<form id="form1" runat="server">
<asp:WebPartManager ID="WebPartManager1" runat="server">
<Personalization Enabled="false" />
</asp:WebPartManager>
<asp:WebPartZone ID="WebPartZone1" runat="server" Width = "100%">
// add the webpart here
I want to add my webpart in the aspx page as a control. My query is how do i make my webpart class as a control so that i can re-use it across the aspx pages