Home General
Options

using ToHtmlString from the nuget package doesn't include controls

Hello,

I am using Linqpad.runtime v8.3.7 in a .net8 asp core project in visual studio.

I have been using Util.ToHtmlString to show enumerables without issues, now I am trying to add a check box to my data but it doesn't seem to work. I have tried with TextBox as well and the body remains empty.

The only way I managed to get html from controls is to request the HtmlContent from it but it doesn't work for me if I try to compose a page with different items on it.

`
var html = Util.ToHtmlString(true, 100, new object[]{ new TextBox("Test"){ Visible = true},/I want to add tables and other controls here/ });
//no textbox
Console.WriteLine(html);

        Console.WriteLine();
        Console.WriteLine();

        var w = Util.CreateXhtmlWriter();
        w.Write(new TextBox("Test").HtmlElement);
        //no textbox
        Console.WriteLine(w.ToString());

        Console.WriteLine();
        Console.WriteLine();

        html = new TextBox("Test").HtmlElement.ToString();
        Console.WriteLine(html);

        Console.ReadKey();

`

Is it expected or am I doing wrong

Thanks for your help.

Comments

  • Is it expected

    I really don't know what to expect!

    I am trying to add a check box

    Why?

    I'm not sure what you are trying to achieve and I don't really see the point of a CheckBox unless you have it hooked up to an event in your script that does something when you click the checkbox, but that doesn't make sense when you are just producing an HtmlString for use outside of LinqPad.

    If you are just attempting to include something that looks like a checkbox (e.g. if you are trying replicate a form which will be printed) then you can just include \u2610 ☐ or \u2610 ☑

  • That's right - the LINQPad controls are intended to be dumped, otherwise two-way connection between the HTML control and your C# code is not established.

    However, if you don't need that interaction, it should still work. The following works for me:

    var html = Util.ToHtmlString (true, 100, new object[] { new LINQPad.Controls.TextBox ("Test") { Visible = true } });
    File.WriteAllText ("test.html", html);
    Util.DisplayWebPage (Path.GetFullPath ("test.html"));
    
Sign In or Register to comment.