views:

1065

answers:

1

Hi All,
I have very simple html report generated from one of my objects on server. I generate html code at PageLoad because I need to clear that object from session and don't want ask external web service for data after user clicks on linkbutton.
Roughly idea is that user clicks on button on page and the report will be displayed at new window.
As I said I have html generated at PageLoad and right now stored in unique file at server. I also thought that I could hide the html code in hidden control. But that wont work without extra work, that would convert html code into some nonsense string and restored later on. I can manage to display my html code into current window by using Response.Write(myhtml as string);
So my question are:
1) where could I store my html code beyond file system (that is tricky with security issues)
2) how to display my htmlcode into new window on click event. What way could I use.

Any comment most welcome..Thanks, X.

I found one possible solution described here.

UPDATE: just adding pieces of code. It displays html string in current window which is not exactly 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();
}
A: 

One big question, is why do you need to clear the object from Session? Why cant you keep the object in session until after the string is displayed in the new window?

You could open an aspx page in the new window, use the string object stored in the session to output the html, and clear the session once the html is displayed.

Victor
as html report is optional feature and user can go out of my scope where I dont have control over the object hence I want to clear all my marks before user leaves.
Xabatcha
i see. i guess i think that since you have to display the report in another window, you still have control of that display and it is within your scope; why not remove the session in the page where you will display the report?
Victor
but what if user dont open report than session stays?
Xabatcha
I understand your concern. an option is to clear all elements of the session, just keep the html string. If user doesnt open report; then yes, session stays, but not for long as it will expire. You can also use the Session-End event in the Global.ascx file to do clean up if you need to do so.
Victor