2014-10-07 73 views
0

我需要澄清的天氣我可以將網頁保存到的StringBuilder或點擊一個按鈕爲HTML格式的字符串數據保存當前網頁作爲字符串與標籤

我的HTML頁面

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form2" runat="server"> 
    <div onload="disableBackButton();"> 


    <table align="center" width="100%" cellpadding="0" cellspacing="0"> 

    <tr> 
    <td> 


     <table align="center" width="100%" cellpadding="0" cellspacing="0"> 
     <tr> 
       <td> 

         <div style="padding: 5px; cursor: pointer; vertical-align: middle;"> 
          <div style="float: left; font-size:large; color:Blue; width: 358px;"> 
          ( Heading)&nbsp;</div> 
          <div style="float: left; margin-left: 20px;"> 
           </div> 
          <div style="float: right; vertical-align: middle;"> 
          </div> 
         </div> 

       </td> 
      </tr> 
      <tr> 
       <td> 


         <table cellpadding="5"> 
          <tr > 
           <td align="left" valign="top" style="height: 18px"> 
            <asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="#003399" Font-Size="14pt" 
             Font-Names="Times New Roman" Text="Name"></asp:Label> 
           </td> 
           <td style="width: 175px"> 
            <asp:TextBox ID="TextBox1" runat="server" Width="170px" Height="20px"></asp:TextBox> 

           </td> 
           <%--<td width="320px">--%> 
           <td width="250px"> 


           </td> 
           <td> 
           <asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="#003399" Font-Size="14pt" 
             Font-Names="Times New Roman" Text="Date"></asp:Label> 
           </td> 
           <td> 
           <asp:TextBox ID="txtDate" runat="server" Width="120px" Height="20px" 
             ReadOnly="True"></asp:TextBox> 



           </td> 



          </tr> 

         </table> 
         <table> 
     <tr> 
     <td align="center" colspan=2 width="780px"> 



     </td> 
     </tr> 
     <tr> 
     <td align="Left" colspan=3 style=" font-size:18Px; font-family:Times New Roman"> 
      data ///// 
     <br /> 

     <br /> 

     data// 

     <br> 
     <br /> 
     Please answer every question. 
     <br /> 
     <br /> 


     </td> 
     </tr> 
     <tr > 
     <td style="height: 20px; width: 550px;" align=center> 
      <asp:Label ID="Label3" runat="server" 
       Text="question." Font-Bold="True" 
       Font-Size="20px" Font-Underline="True" ForeColor="Navy" 
       Font-Names="Times New Roman"></asp:Label> 
     </td> 
     <td style="height: 20px; width: 240px;" align=center colspan="2"> 
     <asp:Label ID="Label4" runat="server" 
       Text="Click Your Response" Font-Bold="True" 
       Font-Size="20px" Font-Underline="True" ForeColor="Navy" 
       Font-Names="Times New Roman"></asp:Label> 
     </td> 
     </tr> 
     <tr> 
     <td align="Left" style=" font-size:18Px; font-family:Times New Roman" height="45px"> 
     1. hi do you have car 

     </td> 
     <td align="center" width="100px" height="35px"> 
      <asp:RadioButton ID="RadioButton1" CssClass="scaledRadioButton" runat="server" GroupName="Question1" 
       Text="Yes" Font-Size="12px" Height="20px" Width="49px"/> 
      </td> 
      <td align="left" width="100px" height="45px"> 
      <asp:RadioButton ID="RadioButton2" runat="server" 
        GroupName="Question1" Text="No" 
        Font-Size="12px" CssClass="scaledRadioButton" Height="20px" Width="49px"/> 
     </td> 

     </tr> 
     </table> 





    </div> 
    </form> 
</body> 
</html> 

在後面的代碼我結合來自數據庫端的值在負載 這樣

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
     Dim xmldoc As New XmlDocument 
        Dim xmldata As String = "<data><rdBx1>True</rdBx1></data>" 
     Dim stringReader As New StringReader(kioskxml) 
     xmldoc.Load(stringReader) 
     stringReader.Dispose() 

     If (XmlNodeNavigator.InitializeXmlNodeNavigator(xmldata)) Then 

      Dim Q1 As String = XmlNodeNavigator.RetrieveElementValue("//data/rdBx1") 
      If (Q1 = "True") Then 
       RdbtnQ1Yes.Checked = True 

      Else 
       RdBtnQ1No.Checked = True 
      End If 


     End If 

    End Sub 

現在我想保存噸他作爲數據基礎 點擊一個按鈕的HTML數據綁定頁面謝謝

+0

你的意思是網頁的地址?它的HTML? – 2014-10-07 10:20:25

+0

我需要頁面的html @Hrvach – 2014-10-07 10:24:16

+0

你需要什麼保存頁面html?你需要恢復其狀態嗎? – Fabio 2014-10-14 06:38:39

回答

2

如果我理解或多或少,必須渲染頁面的方法

string GetInnerHtml() 
    { 
     using (System.IO.StringWriter sw = new System.IO.StringWriter()) 
     { 
      using (HtmlTextWriter htmlWriter = new HtmlTextWriter(sw)) 
      { 
       Page.RenderChildren(htmlWriter); 
       return sw.ToString(); 
      } 
     } 
    } 

VB.NET版本

Function GetInnerHtml() As String 
     Using sw As New IO.StringWriter 
      Using htmlWriter As New HtmlTextWriter(sw) 
       Page.RenderChildren(htmlWriter) 
       Return sw.ToString() 
      End Using 
     End Using 
    End Function 

如何

public partial class _Default : Page 
{ 

    protected override void Render(HtmlTextWriter writer) 
    { 
     var html = GetInnerHtml(); 

     //Use html string 

     Response.Write(html); 
    } 


    string GetInnerHtml() 
    { 
     using (System.IO.StringWriter sw = new System.IO.StringWriter()) 
     { 
      using (HtmlTextWriter htmlWriter = new HtmlTextWriter(sw)) 
      { 
       RenderChildren(htmlWriter); 
       return sw.ToString(); 
      } 
     } 
    } 
} 
+0

我添加了vb代碼 – Fabio 2014-10-07 10:38:20

+0

感謝vb代碼 – 2014-10-07 10:42:14

+0

無法檢索文本框或複選框 – 2014-10-07 12:00:27

1

使用vb.net你可以得到使用使用下面的代碼頁/ URL頁面前端代碼:

Dim sourceString As new StringBuilder 
    sourceString.Append(CStr(New System.Net.WebClient().DownloadString(Request.PhysicalPath))) 

Request.PhysicalPath會給出當前瀏覽的網頁

+0

感謝或回覆 我需要當前查看頁面作爲字符串按鈕點擊 – 2014-10-07 10:46:48

+0

看到更新 – 2014-10-07 10:53:09

+0

謝謝我現在可以得到當前頁面爲html,但無法獲得文本框的值或複選框檢查 感謝您的結果 – 2014-10-07 11:11:13