2012-08-24 74 views
1

我在網站中有一個名爲First.aspx的頁面,在他的頁面中,我有一個簡單的asp.net按鈕。如何在asp.net中動態創建一個.aspx頁面

我想要的,那個按鈕的點擊事件,使一個新的動態「頁面」,可以在一個新的窗口或標籤中打開什麼。

我該如何做到這一點?

新的頁面是不是在網站上,這個網頁創建需要在運行時創建的,需要是動態的。

+2

那你試試? – harry180

回答

0

不知道你爲什麼會想時,你可以通過在數據庫中存儲信息獲得類似的結果,並有一個通用的頁面「模板」從數據庫中讀取並填充取決於其他一些信息,如頁面創建的物理頁網址...

無論如何,這裏是你的問題的解決方案,儘管有些老了...... creating aspx page dynamically in aspnet

1

我建議來。正如您使用的是服務器端語言。你不需要物理創建一個頁面。您可以通過在網站上實施路由,根據URL類型來動態顯示頁面內容。

+0

請問我可以給我一個例子的資源。 – Rod

+0

@Rod這裏是一個鏈接http://msdn.microsoft.com/en-us/library/vstudio/dd329551(v=vs.100).aspx – Rab

2
protected void Button1_Click(object sender, EventArgs e) 
    { 

     File.Copy(Server.MapPath("") + "\\abc.aspx", (Server.MapPath("") + "\\" + TextBox1.Text + ".aspx")); 
     File.Copy(Server.MapPath("") + "\\abc.aspx.cs", (Server.MapPath("") + "\\" + TextBox1.Text + ".aspx.cs")); 

     //.aspx Page 

     StreamReader sr = new StreamReader(Server.MapPath("") + "\\" + TextBox1.Text + ".aspx"); 
     string fileContent = sr.ReadToEnd(); 
     sr.Close(); 
     using (StreamWriter Sw = new StreamWriter(Server.MapPath("") + "\\" + TextBox1.Text + ".aspx")) 
     { 
      fileContent = fileContent.Replace("abc", TextBox1.Text); 
      Sw.WriteLine(fileContent); 
      Sw.Flush(); 
      Sw.Close(); 
     } 

     //.aspx.cs Page 

     StreamReader sr1 = new StreamReader(Server.MapPath("") + "\\" + TextBox1.Text + ".aspx.cs"); 
     string fileContent1 = sr1.ReadToEnd(); 
     sr1.Close(); 
     using (StreamWriter Sw1 = new StreamWriter(Server.MapPath("") + "\\" + TextBox1.Text + ".aspx.cs")) 
     { 
      fileContent1 = fileContent1.Replace("abc", TextBox1.Text); 
      Sw1.WriteLine(fileContent1); 
      Sw1.Flush(); 
      Sw1.Close(); 
     } 

    } 
+0

不錯@mair阿里它的工作原理... –