locked
Return cursor on Postback RRS feed

  • Question

  • User1510859543 posted

    We have a page that uses MaintainScrollPositionOnPostback="true" at top of page and we changed our ListView to a scrolling table with the column headings locked in place. Now when we select to edit a row that is scrolled down from the top the postback does not return the cursor to the row being edited.  Is there a way to do this in jquery?  Thanks.

    Wednesday, January 4, 2017 10:34 PM

Answers

  • User-271186128 posted

    Hi dlchase,

    Is there a way to do this in jquery?

    The MaintainScrollPositionOnPostback is working, but it returns to the edit textbox.

    Please use the jquerysession plugin to do this.

    For example:

    <form id="form1" runat="server">
    <div id="table"  style="overflow: auto; height: 500px;">
    <asp:GridView ID="GridView1" CssClass="Grid" runat="server" AutoGenerateColumns="false" PageSize="10">
    <Columns>
    <asp:BoundField DataField="TradeName" HeaderText="Trade Name" />
    <asp:BoundField DataField="TestMethod" HeaderText="Test Method" />
    <asp:BoundField DataField="TestDescription" HeaderText="Test Description" />
    <asp:BoundField DataField="TestReferenceResult" HeaderText="Test Reference Result" />
    <asp:BoundField DataField="UpdatedDate" HeaderText="Updated Date" />
    <asp:BoundField DataField="UpdatedBy" HeaderText="UpdatedBy" />
    <asp:TemplateField>
    <ItemTemplate>
    <asp:Button ID="btn" runat="server" OnClientClick="gotoedit(this);" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </div>
    <asp:TextBox ID="edit" runat="server" />
    <asp:Button runat="server" ID="button" OnClick="Page_Load" OnClientClick="back(this)" />
    
    
    </form>
    
    <script type="text/javascript">
    $(document).ready(function () {
    if ($.session.get('scrollTop') != "" && $.session.get('scrollLeft') != "") {
    $('#table').scrollLeft($.session.get('scrollLeft'));
    $('#table').scrollTop($.session.get('scrollTop'));
    }
    });
    
    function gotoedit(x) {
    $(window).scrollTop($("#edit").offset().top);
    $.session.set('location', x.id)
    $.session.set('scrollLeft', $('#table').scrollLeft())
    $.session.set('scrollTop', $('#table').scrollTop())
    }
    
    function back(x) {
    $(window).scrollTop($("#" + $.session.get('location')).offset().top);
    }
    

    Best regards,
    Billy

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 5, 2017 8:18 AM

All replies

  • User-271186128 posted

    Hi dlchase,

    Is there a way to do this in jquery?

    The MaintainScrollPositionOnPostback is working, but it returns to the edit textbox.

    Please use the jquerysession plugin to do this.

    For example:

    <form id="form1" runat="server">
    <div id="table"  style="overflow: auto; height: 500px;">
    <asp:GridView ID="GridView1" CssClass="Grid" runat="server" AutoGenerateColumns="false" PageSize="10">
    <Columns>
    <asp:BoundField DataField="TradeName" HeaderText="Trade Name" />
    <asp:BoundField DataField="TestMethod" HeaderText="Test Method" />
    <asp:BoundField DataField="TestDescription" HeaderText="Test Description" />
    <asp:BoundField DataField="TestReferenceResult" HeaderText="Test Reference Result" />
    <asp:BoundField DataField="UpdatedDate" HeaderText="Updated Date" />
    <asp:BoundField DataField="UpdatedBy" HeaderText="UpdatedBy" />
    <asp:TemplateField>
    <ItemTemplate>
    <asp:Button ID="btn" runat="server" OnClientClick="gotoedit(this);" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </div>
    <asp:TextBox ID="edit" runat="server" />
    <asp:Button runat="server" ID="button" OnClick="Page_Load" OnClientClick="back(this)" />
    
    
    </form>
    
    <script type="text/javascript">
    $(document).ready(function () {
    if ($.session.get('scrollTop') != "" && $.session.get('scrollLeft') != "") {
    $('#table').scrollLeft($.session.get('scrollLeft'));
    $('#table').scrollTop($.session.get('scrollTop'));
    }
    });
    
    function gotoedit(x) {
    $(window).scrollTop($("#edit").offset().top);
    $.session.set('location', x.id)
    $.session.set('scrollLeft', $('#table').scrollLeft())
    $.session.set('scrollTop', $('#table').scrollTop())
    }
    
    function back(x) {
    $(window).scrollTop($("#" + $.session.get('location')).offset().top);
    }
    

    Best regards,
    Billy

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 5, 2017 8:18 AM
  • User1510859543 posted

    I tried this in my page but it did not work.  I am unclear as to what the 2nd button outside the GridView is for.  I am using a ListView and added the OnClientClick="gotoedit(this)" on the link button that opens up the edit for the row.  Does it matter that this is a content page and has a master page?

    Thursday, January 5, 2017 2:27 PM
  • User1510859543 posted

    Got it to work. Because it was a ListView I had to place the DIV inside the LayoutTemplate.

    Friday, January 6, 2017 5:51 PM