如何将 html 内容保存到未保存到数据库中的文件中

本文关键字:保存 数据库 文件 html | 更新日期: 2023-09-27 18:36:00

我正在练习我的第一个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客户端何时要查看他们的信息。

如何将 html 内容保存到未保存到数据库中的文件中

您可以使用查询字符串将值从一个页面传递到另一个页面,尽管还有许多其他方法。

这是我的编辑个人资料.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);
    }

现在您可以在 ViewProfile 上获取这些值.aspx.cs如下所示

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" );