public RenderControl ( System.Web.UI.HtmlTextWriter writer ) : void | ||
writer | System.Web.UI.HtmlTextWriter | |
return | void |
// Create a new instance of a Button server control Button myButton = new Button(); myButton.Text = "Click me!"; // Create a new StringWriter object to hold the HTML output StringWriter sw = new StringWriter(); // Render the Button control into the StringWriter object myButton.RenderControl(new HtmlTextWriter(sw)); // Print out the HTML that was generated Console.WriteLine(sw.ToString());
// Create a new instance of a Table server control Table myTable = new Table(); // Add some rows and cells to the table for (int i = 0; i < 3; i++) { TableRow tr = new TableRow(); for (int j = 0; j < 3; j++) { TableCell tc = new TableCell(); Label lbl = new Label(); lbl.Text = $"Row {i}, Column {j}"; tc.Controls.Add(lbl); tr.Cells.Add(tc); } myTable.Rows.Add(tr); } // Create a new StringWriter object to hold the HTML output StringWriter sw = new StringWriter(); // Render the Table control into the StringWriter object myTable.RenderControl(new HtmlTextWriter(sw)); // Print out the HTML that was generated Console.WriteLine(sw.ToString());This example creates a new Table control, adds some rows and cells to it, and then renders the entire table to an HTML writer using the RenderControl method. This example demonstrates how to use the RenderControl method to generate HTML markup for multiple server controls, including child controls. The RenderControl method is a member of the System.Web.UI.Control class, which is part of the System.Web.UI namespace. This namespace is included in the System.Web.dll assembly, which is part of the .NET Framework Class Library. Therefore, to use the RenderControl method, developers need to reference the System.Web.dll assembly in their C# project.
public RenderControl ( System.Web.UI.HtmlTextWriter writer ) : void | ||
writer | System.Web.UI.HtmlTextWriter | |
return | void |