You must Sign In to post a response.
  • Category: ASP.NET

    Listbox goes top during postback in asp.net c#

    Hi sir,
    I have a listbox that contains 30 items in the list and set the autopostback to true. During the postback, listbox goes to top position.
  • #751145
    Hi,

    Are you placed the listbox in "div" tag. or you can place the listbox by creating the table in Aspx page.

    -----------------------------------------------------------------------------
    Regards,
    Gopi A.
    +91 9894315571
    Skype:gopi.net
    http://asaigopi-dotnet.blogspot.in/

  • #751153
    Hi,
    I placed the listbox inside the update panel, it i select the 20th item in listbox , i set autopostback to true, because of this property it will goes to top position of listbox. My problem is how to maintain the selected position of listbox during autopostback event. Kindly give me the solution for this problem.


    <asp:UpdatePanel ID="updatepanel1" runat="server">
    <ContentTemplate>
    <table>

    <tr>

    <td class="lbl">
    School Name
    </td>
    <td>
    <asp:ListBox ID="list_schoolname" AutoPostBack="true" CssClass="ctr150" Height="200px" Width="250px"
    SelectionMode="Multiple" runat="server" onchange="lstSelection();"
    onselectedindexchanged="list_schoolname_SelectedIndexChanged"></asp:ListBox>
    </td>

    </tr>
    </table>

    </ContentTemplate>
    </asp:UpdatePanel>

  • #751155
    Hi,

    Can you please attach the screen shots for the same before postback and after postback..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #751245
    Try setting the Scroll position in script to avoid it as below




    <script type="text/javascript">


    var scr = Sys.WebForms.PageRequestManager.getInstance();


    scr.add_beginRequest(beginRequest);


    function beginRequest()
    {
    scr._scrollPosition = null;
    }


    </script>

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #751252
    Hi Anil Kumar,
    Where can i put the above javascript code. I tried like below, but it is not working. Kindly tell me the solution for this problem.


    <script type="text/javascript" >
    function lstSelection() {

    var scr = Sys.WebForms.PageRequestManager.getInstance();


    scr.add_beginRequest(beginRequest);

    scr._scrollPosition = null;

    var listbox = document.getElementById('<%= list_schoolname.ClientID %>');
    var selIndex = listbox.selectedIndex;

    if (selIndex >= 0) {
    var selValue = listbox.options[selIndex].value;
    var selText = listbox.options[selIndex].text;

    if (selText == "ALL") {
    for (var count = 0; count < listbox.options.length; count++) {
    if (listbox.options[count].text != "ALL") {
    listbox.options[count].selected = false;
    }
    }
    }
    }
    }
    </script>




    <asp:ListBox ID="list_schoolname" AutoPostBack="true" CssClass="ctr150" Height="200px" Width="250px"
    SelectionMode="Multiple" runat="server" onchange="lstSelection();"></asp:ListBox>


  • Sign In to post your comments