Hi nauna,
Check this example. Now please take its reference and correct your code.
HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function ScrollPanelBottom() {
var text = $('[id*=Panel2]');
text.scrollTop(text[0].scrollHeight);
};
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
var text = $('[id*=Panel2]');
text.scrollTop(text[0].scrollHeight);
}
});
};
</script>
<asp:ScriptManager runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<br />
<div class="comment">
<asp:Panel ID="Panel2" runat="server" Height="100px" ScrollBars="Vertical" Style="background-color: antiquewhite;">
<asp:UpdatePanel runat="server" ID="upecompetechatlist" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="timer" runat="server" Interval="1000" OnTick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="lbltext" runat="server" Text="Text"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
</div>
Code
C#
static int a = 31;
protected void Timer1_Tick(object sender, EventArgs e)
{
// your stuff to refresh after some interval
lbltext.Text += "<br/> Message " + a;
a++;
}
protected void Button1_Click(object sender, EventArgs e)
{
string script = "window.onload = function() { ScrollPanelBottom(); };";
ClientScript.RegisterStartupScript(this.GetType(), "message", script, true);
}
VB.Net
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
lbltext.Text += "<br/> Message " & a
a += 1
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim script As String = "window.onload = function() { ScrollPanelBottom(); };"
ClientScript.RegisterStartupScript(Me.GetType(), "message", script, True)
End Sub
Screenshot