2013-10-19 180 views
0

我正在練習我的第一個html示例。如何將html內容保存到不保存到數據庫中的文件

我有EditProfile.htm頁:

<body> 
    <div align="center"> 
     <form id="user-edit-form" action="" method="POST"> 
      <table> 
       <tr> 
        <td>Display Name</td> 
        <td> 
         <input id="txtusername" type="text" style="width: 260px" />   
        </td> 
       </tr> 
       <tr> 
        <td>Real Name</td> 
        <td> 
         <input id="txtrealname" type="text" maxlength="100" style="width: 260px" /> 
        </td> 
       </tr> 
       <tr> 
        <td>Email</td> 
        <td> 
         <input id="txtmail" type="text" maxlength="100" style="width: 390px" /> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <input id="submit" type="submit" value="Save Profile"/> 
        </td> 
       </tr> 
      </table> 
     </form>  
    </div> 
</body> 

客戶將填補textboxes,我希望所有在輸入的值將被保存(不保存到SQL數據庫的方式),然後客戶端點擊:ViewProfile.htm (或.aspx) - >頁面會顯示所有提供的信息。

你可以給我一些解決方案或建議或鏈接,文件來做到這一點。

  1. 如何我都可以在EditProfile.htm頁面由客戶端提供在輸入的值保存到一個文件(XML,... ???)的文件夾中?

  2. 然後,當客戶端想要查看他們的信息時,如何獲取新文件(xml,...?)中的所有信息:ViewProfile.htm

+0

好wprofile.aspx.cs,你想只有HTML辦呢? HTML,不能單獨做,沒有另一個客戶端語言,如C++或VB.NET ... HTML只是服務器端語言... – Seazoux

+0

html,c#aspx頁面也 –

+0

哪一個是你的C#代碼? – Seazoux

回答

0

您可以通過查詢字符串傳遞從一個網頁到另一個值,雖然有很多其他的方法太

這是我editprofile.aspx頁

<form id="form1" runat="server"> 
    <div align="center"> 

      <table> 
       <tr> 
        <td>Display Name</td> 
        <td> 
         <asp:TextBox ID="txtDisplayName" runat="server"></asp:TextBox>   
        </td> 
       </tr> 
       <tr> 
        <td>Real Name</td> 
        <td> 
         <asp:TextBox ID="txtRealName" runat="server"></asp:TextBox>   
        </td> 
       </tr> 
       <tr> 
        <td>Email</td> 
        <td> 
         <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>   
        </td> 
       </tr> 
       <tr> 
        <td> 
         <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"></asp:Button> 
        </td> 
       </tr> 
      </table> 

    </div> 

    </form> 

在代碼中的這個背後頁面我通過查詢字符串傳遞值

protected void Button1_Click(object sender, EventArgs e) 
    { 
     Response.Redirect("Viewprofile.aspx?DisplayName=" + txtDisplayName.Text + "&RealName=" + txtRealName.Text+"&Email="+txtEmail.Text); 
    } 

現在您可以在Vie上獲取這些值這樣

string displayName = Request.QueryString["DisplayName"]; 
string realName= Request.QueryString["RealName"]; 
string email= Request.QueryString["Email"]; 

爲了保存在XML文件中的這些值,你可以試試這個

XDocument doc = new XDocument(new XElement("myXML", 
              new XElement("DisplayName", displayName), 
              new XElement("RealName", realName), 
              new XElement("Email", email) 
) ); 
     doc.Save("D:\\temp.xml"); 
+0

謝謝,我已經知道了,你能告訴我如何保存displayName,realName,email ??? –

+0

你想把它保存在哪裏? –

+0

我想將它保存到我的web項目文件夾中的一個文件(可能是xml文件或...) –