Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Adding WebUserControls to table (http://www.velocityreviews.com/forums/t773429-adding-webusercontrols-to-table.html)

Svein Terje Gaup 06-02-2004 10:41 PM

Adding WebUserControls to table
 
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



Svein Terje Gaup 06-03-2004 09:35 PM

Re: Adding WebUserControls to table
 
Found the solution in the "Portal Starter Kit" at http://www.asp.net.

To insert a UserControl into a PlaceHolder, this is the code to use:
MyPlaceHolder.Controls.Add(Page.LoadControl("~/WebUserControls/UserControl.a
scx"));

Sincerely
Svein Terje Gaup

"Svein Terje Gaup" <stgaup@broadpark.no.spam> wrote in message
news:eVxJ9KPSEHA.3988@tk2msftngp13.phx.gbl...
> 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
>
>





All times are GMT. The time now is 04:55 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.