【问题标题】:How to Render a asp control to HTML?如何将asp控件呈现为HTML?
【发布时间】:2014-10-14 11:39:00
【问题描述】:

我的应用程序我需要一个asp页面的html版本所以我开始通过使用将asp转换为html

在sn-p下面

Public Function GetInnerHtml()
  Dim allTextBoxValues As String = ""
  Dim c As Control
  Dim childc As Control
  For Each c In Page.Controls
    For Each childc In c.Controls
      allTextBoxValues &= RenderControlToHtml(childc)
    Next
  Next
  Return allTextBoxValues
End Function

Public Function RenderControlToHtml(ByVal ControlToRender As Control) As String
  Try
    Dim sb As New System.Text.StringBuilder()
    Dim stWriter As New System.IO.StringWriter(sb)
    Dim htmlWriter As New System.Web.UI.HtmlTextWriter(stWriter)
    ControlToRender.RenderControl(htmlWriter)
    Return sb.ToString()

  Catch ex As Exception

  End Try
End Function

但是通过上面的代码,我只能获取标签的 html,但我无法为这样的前端代码生成 html

<div id="Drug" runat="server" > <div>
<asp:RadioButton ID="RdBtnQ2No" runat="server"  GroupName="Question2" Text="No" 
  Font-Size="12px" CssClass="scaledRadioButton" Height="20px" Width="49px"/>

我的意思是在服务器上运行的控件抛出异常

说:

'RadioButton' 类型的控件'RdBtnQ2Yes' 必须放在表单标签内 与运行=服务器。

但是我已经将每个控件都放在了&lt;form runat="server"&gt; 标记中。

【问题讨论】:

  • 尝试使用所有子控件呈现表单本身。
  • @pln Cam u 详细说明
  • 我的想法是在表单 runat 标记上添加一个 ID 并渲染整个内容,但我发现这个错误可能还有更多。 Perhaps try this suggestion.

标签: asp.net vb.net


【解决方案1】:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="plainHtml.aspx.vb" EnableEventValidation="false" Inherits="Default3" %>

我在 .aspx 页面中添加了“EnableEventValidation="false" 现在运行良好

【讨论】:

    猜你喜欢
    • 2010-09-08
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-10
    相关资源
    最近更新 更多