Display large html with CSS.

Answered
0
0

Hi,

I have a string html that contains a large html including CSS for a sticky menu and a “back to top” button”.
If I want to display it in a different page, it works perfectly with code:

byte[] bytes = System.Text.Encoding.UTF8.GetBytes(htmlContent);
using (MemoryStream ms = new MemoryStream(bytes))
{
Application.DownloadAndOpen(“_blank”, ms, $”catalog_{dataValabilitate}.html”);
}

But now I want to display it and replace my application page. I tried with
var p1 = new Page();
var h = new HtmlPanel();
h.Html = html;
h.Dock = DockStyle.Fill;
p1.Controls.Add(h);
p1.Show();
It is displayed, but all button/menu functions are inactive.
In css I have something like
.back-top {
position: fixed;
bottom: 20px;
left: 25px;
background: #3498db;
color: white;
padding: 10px 20px;
border-radius: 50%;
font-size: 18px;
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.back-top:hover {
background: #2c3e50;
}
….
and in html <a href=’#top’ class=’back-top’>↑</a>

Any way to activate CSS actions? Or to display my html instead of application page?

  • You must to post comments
Best Answer
0
0

Using Application.Navigate to access the html file is pretty simple.

Simply add the html file to your project, ie myhtml.html.

Then access it with Application.Navigate.

Application.Navigate(“myhtml.html")

See attached test case.

 

Attachment
  • You must to post comments
0
0

You can do the first approach like this:
string myHtml = "<html><head><style>body{background:blue;}</style></head><body><h1>Hello</h1></body></html>";
string base64Html = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(myHtml));
webBrowser1.Url = new Uri($"data:text/html;base64,{base64Html}");

For the second approach, you can create an endpoint/handler that returns your HTML and navigate to it:
Application.Navigate(“/api/catalog?id=123”);

  • Adrian Zagar
    Thank you for answer. Unfortunatelly, myHTML is too big to use that method. If you khow another method, please advice. Please give more details on second approach, seems interesting!
  • You must to post comments
0
0

Hi Julie,

What I need is that: when specific conditions are met (in parameters, etc; doesn’t concern the topic), I need one of the 2 posibilities:

1. Display the full html (with css, etc) in a webbrowser control. But I wasn’t able to find HOW to execute something like
WebBrowser wb;
wb.html=myHtml; //that doesn’t exist; what can I do?

2. Completely replace my application with myHtml. I tried:
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(html);
using (MemoryStream ms = new MemoryStream(bytes))
{
Application.DownloadAndOpen(“_blank”, ms, $”catalog.html”);
}
Application.Navigate(“javascript:window.close();”);

That works, but the browser display a warning “allow pop-up” or “pop-up blocked” that prevent the opening of the new tab.

The first approach will be better, if you can tell me how to “inject” all html in WebBrowser.

  • JD
    • JD
    • Dec 10, 2025 - 5:12 pm
    Just navigate to the html file and let the browser do the work.
  • JD
    • JD
    • Dec 10, 2025 - 5:14 pm
    In your sample you are using the wrong target.
  • Adrian Zagar
    “Just navigate to the html file and let the browser do the work.” – please elaborate. Application.DownloadAndOpen(“_blank”, ms, $”catalog.html”); is opening a popu-up (new tab) in browser, serving the html as source. Opening pop-ups is tricky because of the browser asking for permision.
  • You must to post comments
0
0

The HtmlPanel control in Wisej.NET is designed to display HTML content, but it doesn’t create a full browser environment. Instead, it renders HTML within Wisej’s own widget framework. Because of this, CSS pseudo-classes like :hover still work correctly, since they are handled by the browser. However, anchor links such as <a href=’#top’> do not behave as they normally would, because HtmlPanel does not create a standard browsing context with typical navigation. In addition, any JavaScript included in your HTML will not be executed.

If you want to display the HTML within your application while keeping the app active, use IFramePanel or WebBrowser control. These create a real iframe/browser context where CSS and anchor links work properly.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.