Search code examples
c#asp.nethtmlpreview

How can I preview html file in another window?


Hy,

In my application I store a html code in a string, for example:

string myHtml = "<html><body><input type ='text' value='hello'/></body></html>";

How can I preview this html in another window pressing some button?

 <asp:Button ID="PreviewButton" runat="server" Text="Preview" OnClick="PreviewButton_Click"/>

I've tried :

protected void PreviewButton_Click(object sender, EventArgs e)
        {
             myHtml = "<html><body><input type ='text' value='hello'/></body></html>";
             Response.Write(myHtml);
             Response.End();
         }

And it works, the preview it's opened but in the same window.. does anyone know how can I open it in another window?

Thanks in advance.

Jeff


Solution

  • You could store the source in a javascript string and use window.open and then write to the new window the source.

    Remeber to escape the source correctly first.