0

I'd like to create a simple

default.aspx default.aspx.cs

page dyamically and store it on the server.

I've used StreamWriter to create the directory and both files

The default.aspx I create doesn't access the codebehind.

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!"";
        }
    }
";

Can this be done? Any advice, thanks!

3
  • I think you're going the long way around to be honest. Why not create the html file for the page directly? Commented Mar 7, 2012 at 16:44
  • I have to do more advanced things like pulling data from files on the server, etc which an HTML file just isn't practical to do. Commented Mar 7, 2012 at 17:30
  • But asp.net only generates html anyway? Otherwise how are you going to compile the pages? Commented Mar 8, 2012 at 8:53

2 Answers 2

1

You can try to use masterpage's codebehind, to hadndle events, and dynamically create only content-pages.

Sign up to request clarification or add additional context in comments.

1 Comment

That's fine but only if I can make the masterpage dynamically as well. I think there is an underlying problem with the way I am trying to dynamically create these pages. I'm hoping someone can recognize that and fix it.
0

Why create a code-behind at all when you can just add that code in the aspx-file? Much simpler and you still have all your page_load events and such

1 Comment

This is what I ended up doing. Thanks and anyone else in the same situation I recommend doing the same thing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.