Scrolling back up with timer
<p>I created a chat application. When ever I add something to textbox and click on enter text add to the databinder and scroll bar goes up. I used a javascript to scroll down on click which is working fine but due to timer, the scroll bar is moving back to top the soon its dragged down. My code follows</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;
#kdiv1
{
    position:relative;
    left:300px;
    top:20px;
    height:400px;
    width:400px;
    overflow:auto;
}
#kdiv2
{
    position:relative;
    top:100px;
    left:300px;
}
&lt;/style&gt;
    &lt;script type="text/javascript"&gt;
    function scrooldown(div) {
        var scrollDiv = document.getElementById(div);
        scrollDiv.scrollTop = scrollDiv.scrollHeight;
        scrollDiv = null;
    }
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server" defaultfocus="text"&gt;
    &lt;div&gt;
        &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"&gt;

        &lt;/asp:ScriptManager&gt;
        &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" RenderMode="Block"&gt;
        &lt;Triggers&gt;
        &lt;asp:AsyncPostBackTrigger ControlID="button1" EventName="Click" /&gt;
        &lt;/Triggers&gt;
        &lt;ContentTemplate&gt;
        &lt;div id="kdiv1"&gt;
           &lt;asp:Repeater ID="Repeater1" runat="server"&gt;
            &lt;ItemTemplate&gt;
            &lt;span&gt;
             &lt;%# DataBinder.Eval(Container.DataItem, "Message") %&gt; &lt;br /&gt;
            &lt;/span&gt;
            &lt;/ItemTemplate&gt;
            &lt;/asp:Repeater&gt;
        &lt;/div&gt;
            &lt;div id="kdiv2"&gt;
            &lt;asp:TextBox ID="text" runat="server"/&gt;
            &lt;asp:Button ID="button1" runat="server" onclick="button1_Click" OnClientClick="scrooldown('kdiv1')" /&gt;
            &lt;/div&gt;
        &lt;/ContentTemplate&gt;
        &lt;/asp:UpdatePanel&gt;
        &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>C# code</p>

<pre><code>protected void button1_Click(object sender, EventArgs e)
    {
        string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=chatserver;" + "UID=root;" + "PASSWORD=********;" + "OPTION=3";
        OdbcConnection MyConnection = new OdbcConnection(MyConString);
        try
        {
            OdbcCommand cmd = new OdbcCommand("INSERT INTO shoutbox(name, message)VALUES(?, ?)", MyConnection);
            cmd.Parameters.Add("@email", OdbcType.VarChar, 255).Value = "something";
            cmd.Parameters.Add("@email", OdbcType.Text).Value = text.Text;
            MyConnection.Open();
            cmd.ExecuteNonQuery();
            MyConnection.Close();
        }
        catch
        {
        }
        try
        {
            MyConnection.Open();
            OdbcCommand cmd = new OdbcCommand("Select message from shoutbox", MyConnection);
            OdbcDataReader dr = cmd.ExecuteReader();
            ArrayList values = new ArrayList();
            while (dr.Read())
            {
                string ep = dr[0].ToString();
                values.Add(new PositionData(ep));
            }
            Repeater1.DataSource = values;
            Repeater1.DataBind();
            text.Text = "";
            UpdatePanel1.Update();
        }
        catch
        {

        }
    }
}
</code></pre>
