0

I am dynamically generating HTML which is stored in a string variable.
I would like to open a new window with a new page created from this HTML.
This seems too simple, but I just cannot find the solution.

I am using ASP.NET 3.5 and VS2008.

Thanks,
Paul.

3 Answers 3

1

Best idea would be to create an http handler, register it in your web.config file to handle the various request paths that you need to have dynamic content for, and then detect the content to display based on HttpContext.Current.Request.Path.

This way you don't have to save any files, and you write from your string variable to the output stream

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

2 Comments

Could you please elaborate on this idea... cannot seem to get by head round it.
You create a class that implements System.Web.Handlers.IHttpHandler (or System.Web.Handlers.IHttpAsyncHandler if you want to create an asynchronous handler). You implement the ProcessRequest (or BeginProcessRequest and EndProcessRequest in the async case) and the HttpContext is passed to you in an argument. Using the QueryString/Form or whatever other inputs you have, decide which piece of generated HTML you have to send back. Generate that html and then write it using Response.Write(str)
0

You can try this in your new page:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

HttpContext.Current.Response.Clear() HttpContext.Current.Response.ClearHeaders() HttpContext.Current.Response.ClearContent()

HttpContext.Current.Response.ContentType = "text/html HttpContext.Current.Response.Write(YourString) HttpContext.Current.Response.Flush() HttpContext.Current.Response.End()

End Sub

1 Comment

Albeit correct, this solution is essentially using the same page and the same url to produce two entirely different pieces of content (the main output or the output of the string variable). Would be nicer to be able to push the dynamic content into a seperate location.
0

Create an .ashx page that takes a query string, e.g. pagebuilder.ashx?pageid=12345

The purpose of this page is simply to lookup in a session id based on the pageid query string. e.g.

var page = Session["PAGE_" + QueryString["pageid"]].ToString();
Response.Write(page);

On the page that generates the html in a variable, store the variable in Session at Page_Init

` ["PAGE_12345"] = generatedHtml;

Then on Page_Load, generate a javascript that opens to the url pagebuilder.ashx?pageid=12345.

That's it. You will be able to open your newly generated html in another window.

Comments

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.