asked on
Protected Sub btnHtml_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHtml.Click
Dim s As String = GetHtmlFromControl(out)
div1.InnerHtml = s
End Sub
Private Function GetHtmlFromControl(ByVal aControl As Control) As String
Dim SB As New StringBuilder
Dim SW As New StringWriter(SB)
Dim htmlTW As New HtmlTextWriter(SW)
aControl.RenderControl(htmlTW)
Return SB.ToString()
End Function
Design page as follows
<%@ Page Language="VB" MasterPageFile="~/Users/File.master" AutoEventWireup="false"
CodeFile="FileGeneral.aspx.vb" Inherits="FileGeneral" Title="Main" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CPH1" runat="Server">
<table class="wrapper" id="tblCont" style="height: 100%; width: 100%;">
<tr>
<td style="height: 100%; width: 100%; vertical-align: text-top;" id="tdMainContainer"
runat="server">
<uc3:PatFileHeader ID="PatFileHeader1" runat="server"></uc3:PatFileHeader>
<h2>
<asp:Label runat="server" ID="lblSection" Text="Defined"></asp:Label>
</h2>
<div style="background-color:Green; width:90px;height:150px" id="out" runat="server">
<asp:Button ID="sa" runat="server" Text ="sadsa" />
<asp:Label ID="asasdas" runat="server" Text ="assadsadsadsadas"></asp:Label>
</div>
ASKER
ASKER
ASKER
public string RenderControl(Control ctrl)
{
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctrl.RenderControl(hw);
return sb.ToString();
}
public
override
void
VerifyRenderingInServerForm(Control
control)
{
ASKER
public string RenderControl(Control ctrl)
{
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctrl.RenderControl(hw);
return sb.ToString();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications
TRUSTED BY
If you want to display the contents of a server control on a web page, it is probably easier to do it with javascript and show it using the innerHtml property.
In the code above you seem to want to move your control onto some other place. You can do that using the Controls collection.