通常情況下,你的數據(除非頁面的CMS,它可以和它發生之外創建)是從UI和應用邏輯分開。
ASPX頁面是你的UI。它控制你如何查看你的數據。 ASPX文件本身應該而不是響應數據被改變。它們應該是靜態的。
對於每個網絡研討會(在運行時)創建頁面webinar_11514.aspx
,您應該簡單地創建一個頁面(在設計時)。您可以通過傳遞查詢字符串參數來告訴它顯示哪個網絡研討會,例如:webinar.aspx?id=11414
。您的Page_Load
函數將檢索該信息並決定如何處理它。
protected void Page_Load(object sender, EventArgs e)
{
//check to see if an ID was provided
if(String.IsNullOrEmpty(Request.QueryString["id"]))
{
//redirect the user to a page where they can select the webinar, or to an error page, or the home page
}
string id = Request.QueryString["id"]; //This will get the 11514 id from the URL.
var webinar = Webinar.LoadById(id); //load the details of the webinar from a database. It doesn't have to be a relational database, it could be XML or JSON files stored in your ~/App_Data folder. You'll probably want to verify that the webinar for the given ID exists before actually pulling it
if(!webinar.IsCurrent)
{
//tell the user the specified webinar is closed, perhaps redirect to an error page
}
//Begin loading UI elements with the details of the webinar
WebinarTitleLbl.Text = webinar.Title;
WebExHyperLink.NavigateUrl = webinar.WebExUrl;
}
如果使用FriendlyURL's包,則可以使URL更清晰。您可以使用webinar/11514
而不是使用webinar.aspx?id=11514
。您不必使用查詢字符串,而是使用通過友好URL提供的Segments屬性。告訴某人去mysite.com/webinar/11514
要比mysite.com/webinar.aspx?id=11514
容易得多。這對搜索引擎也更好。
你確定這是一個很好的設計嗎?看起來像是一場災難。爲什麼不只有一個通用的webinar.aspx頁面,根據通過查詢字符串傳遞的選定網絡研討會顯示不同?例如:'〜/ webinar.aspx?id = 11514'?您也可以調查[FriendlyURL的](http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx)或使用MVC。 – mason 2014-11-05 18:25:17
您是否真的需要努力創建一個設計用於顯示動態內容的頁面?您的場景聽起來像是數據驅動的Web應用程序或內容管理系統的案例。 – Filburt 2014-11-05 18:26:06
這是很好的展示你已經嘗試過什麼,你的思維過程是什麼 – MZaragoza 2014-11-05 18:33:12