question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ComboBox rendered after postback in ItemsControl resets selected value

See original GitHub issue

Hi guys, when I fill list ‘FirstList’ with data after postback and content of repeater (same for gridview) is rendered, comboboxes resets selected values to value of first item in ‘FirstList’.

HTML:

<dot:Button Text="Postback" Click="{command: DoPostback()}" />
    <dot:Repeater DataSource="{value: FirstList}">
        <ItemTemplate>
            <dot:ComboBox SelectedValue="{value: SelectedValue}" DisplayMember="Text" ValueMember="Value" DataSource="{value: _parent.SecondList}">
            </dot:ComboBox>

Selected: {{value: SelectedValue}}
        </ItemTemplate>
    </dot:Repeater>

CS:

    public class TestPageViewModel: DotvvmViewModelBase
    {
        public List<FirstListItem> FirstList { get; set; } = new List<FirstListItem>();
        public List<SecondListItem> SecondList { get; set; } = new List<SecondListItem>();

        public void DoPostback()
        {
            FirstList = new List<FirstListItem>()
            {
                new FirstListItem() { SelectedValue = 1 },
                new FirstListItem() { SelectedValue = 2 }
            };

            SecondList = new List<SecondListItem>()
            {
                new SecondListItem() { Text = "Value1", Value = 1 },
                new SecondListItem() { Text = "Value2", Value = 2 }
            };
        }
    }

    public class SecondListItem
    {
        public int Value { get; set; }
        public string Text { get; set; }
    }


    public class FirstListItem
    { 
        public int SelectedValue { get; set; }
    }

Result after postback (click): result

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MichalOberreitercommented, May 10, 2017

Works like a charm, thx guys!

0reactions
tomashercegcommented, Apr 27, 2017

OK, we’ll dig into this and fix it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Drop Down List Selected Value Gets Reset On PostBack ...
1 Answer 1 ... You can remove the Autopostback="True" so that no postbacks takes place.. ... Autopostback="True" is set whenever you have to...
Read more >
Radcombobox not retaining selected value after postback
The Radcomboxes are losing selected values after postback. Is there a way to retain selected values in a Radcombobox across postbacks?
Read more >
ASPxComboBox resets value upon postback when ...
Open page; The second item is selected [correct] · Select any other item; press "Postback". The new value stays after the postback [correct] ......
Read more >
Runtime Changes for Migration from .NET Framework 4.5.1 ...
NET Framework 4.5 causes values set via a null coalescing operation to not be visible in the debugger immediately after the assignment operation ......
Read more >
Dropdownlist gets reset after postback.
All items are added perfectly but when I want to add selected value from that in DB,On clicking button the dropdownlist gets reset...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found