Foros del Web

Foros del Web (http://www.forosdelweb.com/)
-   .NET (http://www.forosdelweb.com/f29/)
-   -   Como extraer codigo html de los controles de servidor en ejecucion (http://www.forosdelweb.com/f29/como-extraer-codigo-html-controles-servidor-ejecucion-491972/)

Stream 22/05/2007 13:26

Como extraer codigo html de los controles de servidor en ejecucion
 
El siguiente codigo puede que a mas de uno le sea de utilidad. Este ejemplo usa un datagrid para mostrar los datos. Tambien aplica a los controles de asp net 2.0.
El ejemplo extrae el codigo html que asp net genera.
Código:

Dim cnn As New SqlConnection(AppSettings("ActivitiesConnection"))
        Dim adap As New SqlDataAdapter("select * from actividades", cnn)
        Dim dtable As New DataTable
        adap.Fill(dtable)
        Me.DataGrid1.DataSource = dtable
        Me.DataGrid1.DataBind()

        Dim str As String
        Dim strbuild As System.Text.StringBuilder
        Dim strWriter, strWriter2 As System.IO.StringWriter
        strWriter = New System.IO.StringWriter
        strWriter2 = New System.IO.StringWriter

        Dim html As New System.Web.UI.HtmlTextWriter(strWriter)
        'me.datos = control  que contiene todo el html que se quiere obtener
        Me.DataGrid1.RenderControl(html)

        strWriter2 = html.InnerWriter
        strbuild = strWriter2.GetStringBuilder()

        'str contiene todo el html del control
        str = strbuild.ToString()

en donde la variable str se almacena el string del codigo html del datagrid que es mostrado en el cliente.

Salu2


La zona horaria es GMT -6. Ahora son las 22:07.

Desarrollado por vBulletin® Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.