How can I create a dynamic page in asp.net (C #)?

I added the "First.aspx" page in my web application. Inside the First.aspx page, I have a button called btnbutton. "onclick" The event "btnbutton" should open a new dynamic page. How can i do this.? Remember that the newly created dynamic page does not exist in the application. This page must also be created at runtime and dynamic. please help me!

+4
source share
3 answers

If you ask about creating ASP.NET pages at run time, this is not possible. The reason is as follows:

You need to compile ASP.NET code before running it. And this is not possible after your network application has started.

However, if you are asking about navigation between pages, you can use Response.Redirect :

 Response.Redirect("http://www.stackoverflow.com/"); 
+2
source

You can create a new dynamic file on the ASP.net website (not in the ASP.net web application). But there's a problem. After creating the file, the entire site will be reloaded to compile the newly created file. Thus, session data will be lost.

Here is the code to create a new file.

  string fielName = Server.MapPath("~/file.aspx"); //File.Create(fielName); //File.AppendText(fielName); // create a writer and open the file TextWriter tw = new StreamWriter(fielName); // write a line of text to the file 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> "); // close the stream tw.Close(); tw = new StreamWriter(fielName + ".cs"); // write a line of text to the file 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 ""); } } "); // close the stream tw.Close(); 
+1
source

I found a solution in this link, it is so useful: How to create an ASPX page dynamically

+1
source

All Articles