Home
Options

Dumping Checkbox resets it's checked status

Is there any reason why Dumping a checkbox should reset it's checked status?

The following illustrates what I was trying to do.

CheckBox cb1;
CheckBox cb2;
Button btnRun;

void Main()
{
    cb1 = new CheckBox("1").Dump();
    cb2 = new CheckBox("2").Dump();

    btnRun = new Button("Run", btn => Run()).Dump();   
}

void Run()
{
    Util.ClearResults();
    cb1.Dump();
    cb2.Dump();
    btnRun.Dump();
}

Not a big issue, as I can work around it by storing the values before dumping and restoring them afterwards.

Comments

  • Options

    I can replicate here. Played around for a bit but to me it looks like an internal implementation bug in the Checkbox.
    Not sure if this is how you were working around the problem but adding cb1.Checked = cb1.Checked; above Util.ClearResults() resolves the problem.

  • Options

    @ordinaryorange said:
    adding cb1.Checked = cb1.Checked; above Util.ClearResults() resolves the problem.


    Doesn't make sense and yet it works!

    Weird.

  • Options

    Although dumping the same control more than once is permitted, it was never intended as a mainstream use-case, and so has limited support.

    When you call Util.ClearResults, the checkbox element in browser DOM is destroyed, and so any state that's captured only in the DOM is lost. To avoid this, LINQPad would have to query every property from the DOM before destroying a control, which would be inefficient (and unnecessary in nearly all cases). As to why cb1.Checked = cb1.Checked is effective as a workaround, it has the side-effect of caching the Checked attribute in the local Control object that wraps the DOM.

    As an alternative, you can use a DumpContainer to selectively clear content. LINQPad 6 includes AppendContent() and ClearContent() methods to make this easier:

    var dc = new DumpContainer().Dump();
    dc.AppendContent ("hello");
    dc.AppendContent ("world");
    
    new CheckBox("test").Dump();    // We want to keep this
    
    Thread.Sleep(1000);
    dc.ClearContent();      // Clears the "hello" and "world" but not the checkbox.
    
Sign In or Register to comment.