Run javascript on server side
<p>In ASP.NET upon making a button click I need one JavaScript to make its action. I tried <code>OnClientClick</code> function but the problem with this event is first <code>OnClientClick</code> function takes place and then <code>OnServerClick</code> function takes place i.e. first JavaScript function runs and then C# code executes but I need in reverse order first I need to execute C# code and then I have to run the JavaScript. I am using AJAX.NET and ScriptManager in my code. Do scriptmanager helps me anyway? else how to run JavaScript on server side.</p>

<p>I need in the below manner.</p>

<pre><code>Button1_Click(object sender, EventArgs e)
{
    ListBox1.Items.Add(TextBox1.Text); //for example
    ` here I have to run JavaScript `
}
</code></pre>

<p>Is there any way to implement this?</p>

<p><strong>Edit 1:</strong></p>

<p>I need a div to be scrolled down onbuttonclick(on click adds new data to div using databinder and repeater). As said above clientclick is running first but I need to run it after server action.</p>

<p>javascript is..</p>

<pre><code>&lt;script&gt;
            var objDiv = document.getElementById("div1");
            objDiv.scrollTop = objDiv.scrollHeight;
&lt;/script&gt; 
</code></pre>

<p>and </p>

<pre><code>&lt;div id="div1"&gt; //css properties height 200 and width 200 overflow:auto
    &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" /&gt;
    &lt;asp:Timer ID="Timer1" runat="server" Interval="200" /&gt;
    &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"&gt;
    &lt;ContentTemplate&gt;
        &lt;asp:Repeater id="Repeater1" runat="server" &gt;
        &lt;ItemTemplate&gt;
            &lt;%# DataBinder.Eval(Container.DataItem, "Message") %&gt; &lt;br /&gt;
        &lt;/ItemTemplate&gt;
        &lt;/asp:Repeater&gt;
    &lt;/ContentTemplate&gt;
    &lt;Triggers&gt;
        &lt;asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /&gt; 
    &lt;/Triggers&gt;
    &lt;/asp:UpdatePanel&gt;
    &lt;/div&gt;
    &lt;asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"&gt;
    &lt;ContentTemplate&gt;
        &lt;div id="div2"&gt;
            &lt;asp:TextBox ID="tb_message" runat="server" Width="250px" EnableViewState="false" /&gt;
            &lt;br /&gt;
            &lt;asp:Button ID="btn_send" runat="server" Width="250px" Text="Send" 
                onclick="btn_send_Click" /&gt;
        &lt;/div&gt;
    &lt;/ContentTemplate&gt;
    &lt;Triggers&gt;
        &lt;asp:AsyncPostBackTrigger ControlID="btn_send" EventName="click" /&gt;
    &lt;/Triggers&gt;
    &lt;/asp:UpdatePanel&gt;
</code></pre>
