htmlform.aspx

来自「asp.net经典案例资料」· ASPX 代码 · 共 54 行

ASPX
54
字号
<%@ Import namespace="System.IO" %>
<html>
    <head>
        <title>HTML表单举例!</title>
        <script Language="C#" runat="server" >
            void Page_Load()
            {
                NameValueCollection coll;
                if(Request.HttpMethod == "GET")
                {
                    coll = Request.QueryString;   
                }
                else if(Request.HttpMethod == "POST")
                {
                    coll = Request.Form;
                }
                else
                {
                    Text1.Text = "未知的传送方法!";
                    return;
                }

                // Verify if the password is identical
                if( coll["password"] != coll["repassword"] )
                {
                    Text1.Text = "两次输入的密码不同,注册失败!";
                    return;
                }

                try
                {
                    string filename = Request.PhysicalApplicationPath + "\\" + coll["name"] + ".txt";
                    StreamWriter writer = File.CreateText(filename);
                    writer.WriteLine("name={0}", coll["name"]);
                    writer.WriteLine("password={0}", coll["password"]);
                    writer.WriteLine("birthday={0}年{1}月", coll["year"], coll["month"]);
                    writer.WriteLine("description={0}", coll["description"]);
                    writer.Close();
                }
                catch(Exception e)
                {
                    Text1.Text = e.ToString();
                }

                Text1.Text = coll["name"] + "注册成功!";
            }
        </script>
    </head>

    <body>
        <asp:Label id="Text1" runat="server" />
    </body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?