Maintain scroll position in listboxes in updatepanels, NOT the page

后端 未结 5 1800
臣服心动
臣服心动 2020-12-05 21:38

I have a listbox inside an update panel. When I scroll down and select an item, it scrolls back to the top of the listbox. I heard that the dom does not keep track of the

5条回答
  •  鱼传尺愫
    2020-12-05 22:08

    You can still achieve the partial postback using the UpdatePanel containing a ListBox, but prevent it from being overwritten by a new instance by setting the following on the UpdatePanel:

    ChildrenAsTriggers="False"
    

    This as stated in the MSDN:

    Gets or sets a value that indicates whether postbacks from immediate child controls of an UpdatePanel control update the panel's content. Set the ChildrenAsTriggers property to false if do NOT you want postbacks from immediate child controls of the UpdatePanel control to cause an update of the panel's content.

    The one caveat to this is if you are trying to do any other visual manipulation to the ListBox from the server-side (i.e. adding CSS attributes to the items on postbacks), then you will not see them render until another unrelated postback occurs. If all you are doing is making selections than setting ChildrenAsTriggers="False" will work.

提交回复
热议问题