我想从我的文本框中在文件中写入文本,还要在asp.net的另一个文本框中打印文本

时间:2018-09-09 13:30:45

标签: asp.net file io

但是我得到“一个页面只能有一个服务器端Form标记。 “这个错误 Biographiy.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class Biography : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    string nm = TextBox1.Text;
    string cont = TextBox2.Text;
    TextBox3.Text = "We are learning ASP.NET";

    FileStream fs = new FileStream(Server.MapPath("~") + 
 "\\BioFolder\\TextFile.txt", FileMode.Create);
    StreamWriter sw = new StreamWriter(fs);
    sw.WriteLine(nm);
    sw.Close();
    fs.Close();
    FileStream fs1 = new FileStream(Server.MapPath("~") + 
    "\\BioFolder\\TextFile.txt", FileMode.Open);
    StreamReader sr = new StreamReader(fs1);
    string s = sr.ReadToEnd();
    }
}

Biography.aspx

 <%@ Page Language="C#" AutoEventWireup="true" 
 CodeFile="Biography.aspx.cs" 
 Inherits="Biography" %>

 <!DOCTYPE html>

protected void TextBox4_TextChanged(object sender, EventArgs e)
{

}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form2" runat="server">
    <div style="height: 279px">
        <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>

 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"  Width="136px"> 
  </asp:TextBox>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" 
   Text="Read" style="height: 26px" />
        <br />
        <asp:Label ID="Label2" runat="server" Text="Contact No."> 
   </asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox2" runat="server" Width="139px"> 
   </asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="TextBox4" runat="server" 
    OnTextChanged="TextBox4_TextChanged"></asp:TextBox>
        <br />
        <asp:Label ID="Label3" runat="server" Text="Your Biography:"> 
    </asp:Label>
        <br />
         <asp:TextBox ID="TextBox3" runat="server" Height="122px" 
     Width="259px"></asp:TextBox>
      </div>
    </form>
    <p>
    &nbsp;</p>
    <form id="form3" runat="server">
    <div>
    </div>
    </form>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
    </body>
    </html>

我没有走错地方。请帮助我找到错误,任何帮助将不胜感激,在此先感谢

///////////////////////////////////////////////// ///////////////////////////////////////////////////// /////////////////

0 个答案:

没有答案