Mehdi
1/2/2003 4:15:00 PM
Kim,
Thanks for replying.
I converted your VB OnInit to C# syntax, and unfortunately could not manage
it to work.
I think I am going to end up creating a template html page and drop my
UserControls one by one manually into the table cells. Including UserControl
in my BasePage class would have been an ideal solution to my problem.
Thanks anyway.
Best Regards
Mehdi
"Kim Bach Petersen" <msnews@kensho.dk> wrote in message
news:ej6DptlsCHA.2168@TK2MSFTNGP12...
> Mehdi wrote:
> > Hi,
> >
> > I have a BasePage class that all my WebForms are derived from as
> > follow:
> >
> > public class BasePage : System.Web.UI.Page
> > {
> >
> > protected override void Render(HtmlTextWriter writer)
> > {
> > writer.Write( @"<html>
> > <body class=....
> > <TABLE><TR><TD>");
> >
> > SideMenu _sm = new SideMenu();
> > _sm.RenderControl(writer);
> >
> > writer.Write( @"</TD>......");
> >
> > base.Render(writer);
> >
> > writer.Write( @"Some more HTML tags.... + and closing
> > document...");
> >
> >
> > My problem is that the SideMenu UserWebControl is not rendered and not
> > displayed, but if I create a new instance of TextBox in a same way,
> > instead of my SideMenu, it works!
> >
> > I've created my SideMenu which is a WebUserControl in design mode and
> > it contains a HTML table and some text inside cells, using javascript
> > and css. I've not added any code in SideMenu.ascx.cs and if I drag
> > and drop it on a empty WebForm, works OK.
> >
> > What am I doing wrong or missing.
>
> You can't add new controls to a page as late in its lifecycle as
'Render' -
> only literal content. That is: add the controls in 'OnInit' instead: (VB
> example, sorry)
>
> Public Class BasePage : Inherits System.Web.UI.Page
> Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
> Me.Controls.Add(New LiteralControl("<!DOCTYPE HTML PUBLIC '-//W3C//DTD
> HTML 4.0 Transitional//EN'><html><head><title>Hello
> World</title></head><body>"))
> Dim MainForm As New HtmlForm
> MainForm.Id = "mainform"
> Dim MyMenu As New Menu
> MyMenu.Id = "menu"
> MainForm.Controls.Add(MyMenu)
> Me.Controls.Add(MainForm)
> Me.Controls.Add(New LiteralControl("<br /><br /></body></html>"))
> MyBase.OnInit(e)
> End Sub
> End Class
>
> Kim :o)
>
>