以下代码创建 file.aspx 和 file.aspx.cs:
protected void Button1_Click(object sender, EventArgs e)
{
string fielName = Server.MapPath("~/file.aspx");
TextWriter tw = new StreamWriter(fielName);
tw.WriteLine(@"<%@ Page Language=""C#"" AutoEventWireup=""true"" CodeFile=""file.aspx.cs"" Inherits=""file"" %>
<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
<html xmlns=""http://www.w3.org/1999/xhtml"">
<head runat=""server"">
<title></title>
</head>
<body>
<form id=""form1"" runat=""server"">
<div>
</div>
</form>
</body>
</html>
");
tw.Close();
tw = new StreamWriter(fielName + ".cs");
tw.WriteLine(@"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 file : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(""new File "");
}
}
");
tw.Close();
}
我想让页面名称写在我的文本框中。
我曾尝试将文本框放入上述代码的 html 源代码中,但出现错误。
CodeFile="""+TextBox1.Text+""" Inherits="""+TextBox1.Text+"""