Dynamically create an html file and redirect user to it.C#

Dear experts,

I have this  requirement and its getting difficult for me to wrap my head around it.

Need to create an html page and redirect user to that page dynamically on click of a print button.
This new HTML page should populate all the data. Using c # & Asp.net. Where should I start, I got all the data part done.

Please share your thoughts any working examples. Much appreciated.

ps  I don't want to write it to disk

- dAn
Dan SchimoAnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
Without knowing how the page is set up, I do something similar in a web app of mine.

I have a separate class that generates html based on database content.  On the target page, I hae the following:

<asp:Content ID="Content1" ContentPlaceHolderID="BodyContent" runat="server">
    <section class="content container-fluid">
        <div id="ORDERFORM" runat="server">%PAGE_CONTENT%</div>

Open in new window

Then, in my codebehind on page load I call the HTML builder and pass in the data to build.  In this case it's a dynamically generated form that consists of checkboxes, text boxes, or combo boxes.  In the FormBuilder, I pass the id of the content to generate, then it gets the content data and assembles the HTML for the page which returns as a string.  I set the InnerHTML of the content to this result.

ORDERFORM.InnerHtml = FormBuilder.BuildOrderForm(Session["OrderOptionsID"].ToString());

Open in new window

You can handle generating that HTML however you want in C#.
Dan SchimoAnalystAuthor Commented:
Thanks for the reply.

1. The target page is a basic html page with .html in the URL
I am trying to display only data from database, no forms.

This basically used to print data entered in to form.
Dustin SaundersDirector of OperationsCommented:
Then you can use Javascript to generate the form, but basically the same theory.  Just have a Javascript function on page load that builds the data and sets an element's InnerHTML to your generated one.

You can use a WebMethod to get the data from an ajax call and build the form off data that way.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
Need to create an html page and redirect user to that page dynamically on click of a print button.
This new HTML page should populate all the data.

there is no issue to generate HTML content via C# or other programming language but you got to re-think if you really want to generate those static HTML content?

that would be a problem in future if you wish to update the static HTML content as you need to go through all these generated content and update them accordingly.

why not using a dynamic approach as what Dustin had mentioned? in general, you can create a server side page (like .aspx ASP.NET page) by accepting parameter(s) in order to generate your dynamic content.

By using server side page, you can also protect the content if necessary, but it would be difficult to do so by using static HTML pages.
Dan SchimoAnalystAuthor Commented:
Thanl you Dustin for your input. Ryan appreciate your insight.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.