ASP.Net Listbox: keep scrollable list position after partial postback (not scrolling site!)

On the ASP.Net page, I have a list. When the selected items in it are changed, the drop-down list is activated or deactivated depending on the item, and again, another item in the drop-down list is selected depending on the item in the list.

I cannot execute the onSelectedItemChanged action from a list in javascript because I need to query two different databases for the action.

The problem is that whenever a site receives a partial postback from an event with a change of choice in the list, the selected list item always scrolls up (in IE) or bottom (in chrome) of the list. This is extremely annoying for the user.

Here is what the list looks like before the user selects an item enter image description here :

Now the user selects the item, the event handler for selectchanged is called, fills the drop-down list below with data, and partial postback occurs. In this example, the user clicks the "Klärschlamm" item in the 4th list. After the postback, it looks like this:

enter image description here

A suddenly selected item is at the top of the list, not at the bottom when it was selected, when it was selected.

What can I do to maintain the scroll position of the list after postback? I tried many “solutions” that I found on the web, wrapping the list and drop-down list in updatable panels using javascript Begin- and EndRequestHandlers, etc. None of the solutions found changed anything, alas.

Here's the XAML I use:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AbfallEdit.aspx.cs" %> <asp:UpdatePanel runat="server" UpdateMode="Always" ChildrenAsTriggers="True"> <ContentTemplate> <asp:ListBox id="list" clientidmode="Static" runat="server" AutoPostBack="True" OnSelectedIndexChanged="updateKontamination" /> </ContentTemplate> </asp:UpdatePanel> <asp:UpdatePanel runat="server"> <ContentTemplate> <asp:DropDownList ID="drop" runat="server" /> </ContentTemplate> </asp:UpdatePanel> 

The SelectedIndexChanged event handler makes only some database queries, and then activates the drop-down list and sets the corresponding index. He does nothing with the list itself. And I only databind the listbox if it is not a PostBack.

+4
source share
1 answer

this post is pretty old, but in case someone else has a problem ...

change the markup to

  <asp:UpdatePanel id="upList" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="otherControlToUpdateList" EventName="<EventName>" /> </Triggers> <ContentTemplate> <asp:ListBox id="list" clientidmode="Static" runat="server" AutoPostBack="True" OnSelectedIndexChanged="updateKontamination" /> </ContentTemplate> </asp:UpdatePanel> <asp:UpdatePanel id="upDrop" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="list" EventName="SelectedIndexChanged" /> </Triggers> <ContentTemplate> <asp:DropDownList ID="drop" runat="server" /> </ContentTemplate> </asp:UpdatePanel> 

This should contain an "upList" from starting and rebuilding the "list" when the selection changes.

0
source

Source: https://habr.com/ru/post/1492092/


All Articles