Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I need some help.

Currently, I have a gridview that will update with the timer and also a button when clicked, will update the gridview.

So now, I am currently facing a problem regarding when scrolling the updatepanel/gridview, I would like it to remain at scrollbar position. But when I click on the button, I will like the updatepanel/gridview to return to bottom (already have the javascript).

Thanks in advance!


C#
<div id="scrollChat" style="overflow: auto; width: 80%; height: 250px; margin-left: auto;
        margin-right: auto;">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Timer ID="timer" runat="server" OnTick="timer_Tick" Interval="2000">
        </asp:Timer>
        <asp:UpdatePanel ID="upChat" runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="timer" EventName="Tick" />
            </Triggers>
            <ContentTemplate>
                <asp:GridView ID="gvChat" runat="server" Style="width: 100%;" Font-Names="Verdana"
                    AutoGenerateColumns="True" ShowHeader="False" GridLines="None">
                    <RowStyle Height="25" />
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
        <div id="chat" style="height: 1px;">
        </div>
    </div>
    <div style="width: 100%; height: 100px; text-align: center; margin-removed 30px;">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:TextBox ID="tbMsg" Rows="3" Height="60px" Width="80%" TextMode="multiline" runat="server"
                    Style="margin-bottom: 15px;" Font-Names="Verdana" placeholder="Type your message here..."></asp:TextBox>
                <br />
                <asp:Button ID="btnSend" class="btn btn-primary btn-lg" runat="server" Text="Send"
                    OnClick="btnSend_Click" Width="200px" Font-Bold="true" Font-Names="Verdana" OnClientClick="btnSend_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
     
    <br />
    <br />

    <script type="text/javascript">
        Sys.Application.add_load(function () {
            var t = document.getElementById('scrollChat');
            t.scrollTop = t.scrollHeight;
        });
	</script>
Posted

1 solution

Just wondering if you have already tried by adding MaintainScrollPositionOnPostback="true" in Page tag.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900