How to generate HTML in popup with Asp.Net

I have a very simple html report generated by one of my objects on the server. I am generating html code in PageLoad

because I need to clear this object from session and do not want to request an external web service for data after the user clicks the link button.

The rough idea is that the user clicks a button on the page and the report will be displayed in a new window.

As I said, I have html generated in PageLoad

and right now stored in a unique file on the server. I also thought I could hide the html code in a hidden way. But this will not work without additional work to convert the html code into some meaningless string and subsequently restore it.

I will manage to display my html code in the current window using Response.Write(myhtml as string);

So my question is:

  • Where can I store my HTML outside of the filesystem (which is tricky with security issues)
  • how to display my htmlcode in a new click event window. How can I use.

I found one possible solution described here .

UPDATE:

Just adding code snippets. It displays a html string in the current window, which is not exactly what I want.

private void InitData(){  
  string filename = DateTime.Now.ToString("yyyyMMdd_HHmmssfff");
  lbtnPrintOutOrder.CommandArgument = filename;
  StreamWriter swXLS = new StreamWriter((MapPath("Files\\")) + filename);

  string message = GetEmail();//get data form session object

  swXLS.Write(message);//save data to file
  swXLS.Close();
}

protected void lbtnPrintOutOrder_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{
   string filePath = (MapPath("Files\\")) + e.CommandArgument.ToString();

  string content;
  using (StreamReader reader = File.OpenText(filePath)) {
     content = reader.ReadToEnd();//get html from file
  }
  Response.Write(content);//load it to current window
  Response.End();
}

      

0


source to share


1 answer


One big question, why do you need to clear the object from the session? Why can't you save the object in the session until the string is displayed in a new window?



You can open the aspx page in a new window, use the string object stored in the session to output the html, and clear the session after the html is displayed.

0


source







All Articles