Thank you for the responses. I checked my code and am attaching it here. Like Glenn mentioned, there is database call but nothing is happening till one method (BeginInterview) is called from the parent page.
I included the parameterless constructor and tried it as well.
Below is my code: Stripped some of the render and create child controls for readability sake.
[ToolboxData("<{0}:ServerControl1 runat=server>")]
public class ServerControl1 : CompositeControl, INamingContainer
{
public ServerControl1()
{
}
protected override void OnInit(EventArgs e)
{
if (Page.IsPostBack)
{
if (HttpContext.Current.Session["controlCollection"] != null)
{
foreach (Control c in ControlCollection)
{
Controls.Add(c);
}
}
}
base.OnInit(e);
}
protected override void OnPreRender(EventArgs e)
{
HtmlLink cssLink = new HtmlLink();
cssLink.ID = "ControlStyleSheet.css";
cssLink.Href = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "IWC.CustomControl.Resources.ControlStyleSheet.css");
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");
HtmlLink cssLink2 = new HtmlLink(); ;
if (CSSPath != string.Empty || CSSPath != null)
{
cssLink2.ID = "customStyleSheet.css";
cssLink2.Href = CSSPath;
cssLink2.Attributes.Add("rel", "stylesheet");
cssLink2.Attributes.Add("type", "text/css");
}
bool CssLinkAlreadyExists = false;
foreach (Control headctrl in Page.Header.Controls)
{
if (headctrl.ID == cssLink.ID)
{
CssLinkAlreadyExists = true;
break;
}
}
if (!CssLinkAlreadyExists)
{
Page.Header.Controls.AddAt(0, cssLink);
}
base.OnPreRender(e);
}
protected override void CreateChildControls()
{
panelDropShadow.ID = "panelDropShadow";
panelBackgrnd.ID = "panelBackgrnd";
rightButton.ID = "rightButton";
rightButton.Click += new ImageClickEventHandler(rightButton_Click);
leftButton.ID = "leftButton";
leftButton.Click += new ImageClickEventHandler(leftButton_Click);
imgFinish.ID = "imgFinish";
imgFinish.Click += new ImageClickEventHandler(imgFinish_Click);
imgFinish.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "IWC.CustomControl.Resources.Images.finish_button_v2.jpg");
lbError.ID = "lbError";
string htmlColor = "#c00000";
lbError.ForeColor = System.Drawing.ColorTranslator.FromHtml(htmlColor);
lbMain.ID = "lbMain ";
imgError.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "IWC.CustomControl.Resources.Images.alert_icon.gif");
imgError.CssClass = "IWC_imgError";
lb_Close.Text = "Close";
lb_Close.ID = "lb_Close";
lb_Close.CssClass = "IWC_lbClose IWC_grid-element-green";
lb_Close.Click += new EventHandler(lb_Close_Click);
Controls.Add(panelDropShadow);
Controls.Add(panelBackgrnd);
Controls.Add(leftButton);
Controls.Add(rightButton);
Controls.Add(lbMain);
Controls.Add(imgError);
Controls.Add(lbError);
Controls.Add(lb_Close);
Controls.Add(imgFinish);
if (HttpContext.Current.Session["controlCollection"] != null)
{
ControlCollection.Clear();
ControlCollection = (List<Control>)HttpContext.Current.Session["controlCollection"];
foreach (Control c in ControlCollection)
{
Controls.Add(c);
}
}
}
protected override void RenderContents(HtmlTextWriter writer)
{
panelDropShadow.RenderControl(writer);
panelBackgrnd.RenderBeginTag(writer);
lbMain.RenderControl(writer);
leftButton.RenderControl(writer);
rightButton.RenderControl(writer);
lbError.RenderControl(writer);
imgError.RenderControl(writer);
imgFinish.RenderControl(writer);
lb_Close.RenderControl(writer);
foreach (Control c in ControlCollection)
{
c.RenderControl(writer);
}
panelBackgrnd.RenderEndTag(writer);
}
public void BeginInterview(string SessionID, string UserID, int ScriptID, int ValidLength)
{
ctrl = (MyService)HttpContext.Current.Session["ctrl"];
StartScript(ScriptID, SessionID, UserID, ValidLength);
}
}
your time and help is much appreciated.