[Mono-bugs] [Bug 76815][Nor] New - Controls.Add method not working in HTML objects

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Thu Nov 24 11:15:20 EST 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by gallarr at hotmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=76815

--- shadow/76815	2005-11-24 11:15:20.000000000 -0500
+++ shadow/76815.tmp.2906	2005-11-24 11:15:20.000000000 -0500
@@ -0,0 +1,131 @@
+Bug#: 76815
+Product: Mono: Class Libraries
+Version: 1.1
+OS: Red Hat 9.0
+OS Details: i386
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Sys.Web
+AssignedTo: gonzalo at ximian.com                            
+ReportedBy: gallarr at hotmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Controls.Add method not working in HTML objects
+
+Description of Problem:
+When adding Row objects to an HTML table with the Controls.Add method, they
+are not displayed at all in the HTML page. If added with Rows.Add they will
+be displayed. All of this within the Render event. This was working fine in
+mono 1.1.8.3, got broken at 1.1.9
+
+Steps to reproduce the problem:
+1. Have a "menu" class that is rendered in the Render event of a Page (the
+purpose is to have a menu that can be reused). The menu is a table, filled
+with rows via table.Controls.Add(row), the rows are filled with cells, via
+row.Controls.Add(cell), see the example further down
+
+Actual Results:
+The HtmlTable is not displayed (rendered) at all at the web page
+
+Expected Results:
+HTML code for the table at the web page
+
+How often does this happen? 
+Always
+
+Additional Information:
+It also happens if you add cells with row.Controls.Add instead of row.Cells.Add
+Sample code (WebForm1.aspx.cs)
+------------------------------
+using System;
+using System.ComponentModel;
+using System.Web;
+using System.Web.UI;
+using System.Web.UI.HtmlControls;
+
+namespace WebApplication1
+{
+	//the "MENU" class
+	[DefaultProperty("Text"), 
+	ToolboxData("<{0}:CustomMenu runat=server></{0}:CustomMenu>")]
+	public class CustomMenu : System.Web.UI.WebControls.WebControl
+	{
+		protected override void Render(HtmlTextWriter output)
+		{
+			HtmlTable objTable = new HtmlTable();			
+			HtmlTableRow objRow1 = new HtmlTableRow();
+			HtmlTableCell objRow1Cell1=new HtmlTableCell();
+			HtmlTableCell objRow1Cell2=new HtmlTableCell();
+			HtmlTableCell objRow1Cell3=new HtmlTableCell();
+			
+			objTable.CellPadding = 0;
+			objTable.CellSpacing = 0;
+			objTable.Width = "100%";
+			objTable.Border = 2;
+			objTable.Align = "top";
+			
+			objRow1.Height = "10";
+			objRow1Cell1.Width = "100";
+			objRow1Cell1.InnerHtml = "Menu title";
+			
+			objRow1Cell2.Width = "100";
+			objRow1Cell2.InnerHtml = "option 1";
+
+			objRow1Cell3.Width = "100";
+			objRow1Cell3.InnerHtml = "option 2";
+
+			objRow1.Cells.Add(objRow1Cell1);
+			objRow1.Cells.Add(objRow1Cell2);
+			objRow1.Cells.Add(objRow1Cell3);
+			//with Controls.Add nothing will be displayed
+			objTable.Controls.Add(objRow1);
+			
+			//with Rows.Add will work ok
+			//objTable.Rows.Add(objRow1);		
+						
+			objTable.RenderControl(output);
+			//please note that objRow1.Controls.Add(objcell)
+			//would not work either
+		}
+	}
+
+	//the Web page that uses the menu
+	public class WebForm1 : System.Web.UI.Page
+	{
+		private void Page_Load(object sender, System.EventArgs e)
+		{
+			// Put user code to initialize the page here
+		}
+
+		protected override void Render(HtmlTextWriter writer)
+		{
+			writer.Write( @"
+			<HTML>
+			<HEAD>
+			<TITLE>title</TITLE>
+			</HEAD>");
+			writer.Write( @"<BODY>");
+			CustomMenu m=new CustomMenu();
+			m.RenderControl(writer);
+			writer.Write( @"</BODY>
+			</HTML>");			
+		}
+
+		#region Web Form Designer generated code
+		override protected void OnInit(EventArgs e)
+		{
+			InitializeComponent();
+			base.OnInit(e);
+		}
+		
+		private void InitializeComponent()
+		{    
+			this.Load+=new System.EventHandler(this.Page_Load);
+		}
+		#endregion
+	}
+}


More information about the mono-bugs mailing list