[英]Create ASP.NET page with CodeBehind Dynamically
我想創建一個簡單的
default.aspx default.aspx.cs
動態地翻頁並將其存儲在服務器上。
我使用StreamWriter創建目錄和兩個文件
我創建的default.aspx無法訪問后台代碼。
private string displayPage = @"<%@ Page Language=""C#"" AutoEventWireup=""true"" CodeBehind=""Default.aspx.cs"" %>
<!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>
<asp:Label id=""_lblBody"" runat=""server"" />
<asp:Label id=""_lblFooter"" runat=""server"" />
</div>
</form>
</body>
</html>";
private string codeBehindPage = @"using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
_lblBody.Text = ""Hello World!"";
}
}
";
能做到嗎? 任何建議,謝謝!
您可以嘗試使用母版頁的代碼隱藏,以避開事件,並僅動態創建內容頁。
當您只需將代碼添加到aspx文件中時,為什么還要創建一個代碼隱藏? 簡單得多,您仍然擁有所有的page_load事件,例如
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.