S
Svein Terje Gaup
Hi all,
I have a base class that inherits from System.Web.UI.Page. In this base
class I create a table, with placeholders in the table cells.
In the web page that inherits from the base class, I add controls to the
placeholders. This works fine as long as the controls aren't Web User
Controls. This is the problem. Web User Controls do not show up after I've
added them.
In the base class, I override the Render method like this:
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.RenderBeginTag(HtmlTextWriterTag.Html);
writer.RenderBeginTag(HtmlTextWriterTag.Head);
writer.RenderBeginTag(HtmlTextWriterTag.Title);
writer.Write("TestPage");
writer.RenderEndTag();
writer.RenderEndTag();
MainTable.RenderControl(writer);
writer.RenderEndTag();
base.Render(writer);
}
In MainTable, I've added a placeholder called "Left". I add the
WebUserControl like this in the inheriting class:
private void Page_Load(object sender, System.EventArgs e){
Logout uscLogout = new Logout(); //WebUserControl
uscLogout.ID = "ctrlLogout";
uscLogout.EnableViewState = true;
uscLogout.Visible = true;
Button btn = new Button();
btn.Text = "Click me!";
Test uscTest = new Test();
Left.Controls.Add(uscLogout);
Right.Controls.Add(uscTest);
Left.Controls.Add(btn);
}
MainTable renders as it should, except the WebUserControls I've added to one
of the cells doesn't show up.
If I add a "Button" the same way as I add the WebUserControl, it shows up
just fine.
Also, I had to make remove the "abstract" keyword from the code-behind for
the WebUserControls to be able to instantiate them.
Can anyone spot what's wrong?
Is there a problem with WebUserControls being added like this?
Sincerely
Svein Terje Gaup
I have a base class that inherits from System.Web.UI.Page. In this base
class I create a table, with placeholders in the table cells.
In the web page that inherits from the base class, I add controls to the
placeholders. This works fine as long as the controls aren't Web User
Controls. This is the problem. Web User Controls do not show up after I've
added them.
In the base class, I override the Render method like this:
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.RenderBeginTag(HtmlTextWriterTag.Html);
writer.RenderBeginTag(HtmlTextWriterTag.Head);
writer.RenderBeginTag(HtmlTextWriterTag.Title);
writer.Write("TestPage");
writer.RenderEndTag();
writer.RenderEndTag();
MainTable.RenderControl(writer);
writer.RenderEndTag();
base.Render(writer);
}
In MainTable, I've added a placeholder called "Left". I add the
WebUserControl like this in the inheriting class:
private void Page_Load(object sender, System.EventArgs e){
Logout uscLogout = new Logout(); //WebUserControl
uscLogout.ID = "ctrlLogout";
uscLogout.EnableViewState = true;
uscLogout.Visible = true;
Button btn = new Button();
btn.Text = "Click me!";
Test uscTest = new Test();
Left.Controls.Add(uscLogout);
Right.Controls.Add(uscTest);
Left.Controls.Add(btn);
}
MainTable renders as it should, except the WebUserControls I've added to one
of the cells doesn't show up.
If I add a "Button" the same way as I add the WebUserControl, it shows up
just fine.
Also, I had to make remove the "abstract" keyword from the code-behind for
the WebUserControls to be able to instantiate them.
Can anyone spot what's wrong?
Is there a problem with WebUserControls being added like this?
Sincerely
Svein Terje Gaup