开发者

How to create ASPX Page Dynamically

i have two controls on asp.net page , textbox and button and i want to write new page into开发者_StackOverflow textbox then when i hit the button i want to create new asp.net web page with textbox text. what do you want me to prefer to do this? is there any step by step tutorial or any code you have done before? thanks for asnwers.

ok more detail about what i want.

textbox control text is "contact" and i click my button control. button take textbox text "contact" and create new web form page which name is "contact.aspx and its code page contact.cs" . thats it. just create new web form page under root directory with button click.

maybe there is a single code line like

Page pg =new Page(); pg.create();


You can use File.WriteAllText to write the contents of the textbox to any location that the application pool user has permissions to write to.


From your edit it appears that you are looking for a CMS/wiki kind of functionality. There is nothing like that built into the .NET framework.

I suggest you look for wiki software.


No need to worry about big codes etc

You can create it with 2 simple steps explained in my blog

  1. Create one empty page then copy it using Files concept. Save it as what ever name you want.
  2. Try to change the content inside newly created page to Run smoothly

Please visit my blog for example solution

Click here for Solution Post


You can use the Page.ParseControl method.

Beware, it does not support everything you can do with a real ASPX or ASHX file, but it works for simple things. An example is available here: Using Page.ParseControl to add new control from Control Tag


There is very simple way to do that. It is working on principe to Copy one your Page, you should put Page with controls that you want to use on your other pages. So first you need using System.IO; then you need this code

 protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        File.Copy(Server.MapPath("") + "\\Submit.aspx", (Server.MapPath("") + "\\" + TextBox1.Text + ".aspx"));
        File.Copy(Server.MapPath("") + "\\Submit.aspx.cs", (Server.MapPath("")+ "\\" + TextBox1.Text + ".aspx.cs"));
        Response.Redirect(TextBox1.Text + ".aspx");
    }
    catch
    {
        Response.Write("<script>window.alert('This page is taken. Please change name!')</script>");
    }
}

As you can see, The page you are coping is called Submit, and new Name of your Page is called like textbox1.text. I hope that this helped you and anyone else.


enter link description here Before some time I saw a logical question in a web site in this a person give the problem as like this “I have one page called First.aspx in my web application, in this page; I have a simple asp.net button control. And I want is, on the click event of that button control, create (render) a new dynamic "page" that can be opened in a new windows or tab” . Here we give An Example here to creating a new .aspx page at run time. We also give the option to give page name. The user can give as he/she like. Like Google blogging we make new page at runtime.The new page is not in the website, this page create needs to be created at runtime and needs to be dynamic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜