HtmlTextWriter writer = new HtmlTextWriter(new StringWriter()); // Create a new HTML element writer.RenderBeginTag(HtmlTextWriterTag.Div); // Add some text to the element writer.Write("Hello, world!"); // Close the element writer.RenderEndTag(); // Output the HTML to the response stream Response.Write(writer.InnerHtml);
HtmlTextWriter writer = new HtmlTextWriter(new StringWriter()); // Create a new HTML table writer.RenderBeginTag(HtmlTextWriterTag.Table); // Create a table row writer.RenderBeginTag(HtmlTextWriterTag.Tr); // Create some table cells writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.Write("Cell 1, Row 1"); writer.RenderEndTag(); writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.Write("Cell 2, Row 1"); writer.RenderEndTag(); writer.RenderEndTag(); // End the table row // End the table writer.RenderEndTag(); // Output the HTML to the response stream Response.Write(writer.InnerHtml);This code creates a simple HTML table with two rows and two cells. It shows how the `RenderBeginTag` and `RenderEndTag` methods can be used to create nested HTML elements. Both examples use the `System.Web` namespace, which is part of the `System.Web.dll` package library.