EDIT
Based on the code provided, this should work if you want to register the script on the server side:
Button1_Click(object sender, EventArgs e) { ListBox1.Items.Add(TextBox1.Text); //for example ScriptManager.RegisterStartupScript(UpdatePanel2, UpdatePanel2.GetType(), "scriptKey", "var objDiv = document.getElementById('div1'); objDiv.scrollTop = objDiv.scrollHeight;", true); }
You can also use the code provided by James if you want to register the script on the client side, but keep in mind that the script will be executed every time the AJAX request is completed (The script will be executed every time any update panel is updated). If you are going to scroll div1
every time UpdatePanel1 is updated, and there are no more update panels updated with the Timer
control on the same page, the code provided by James would be more useful while my code would scroll down div1
just a click div1
.
UPDATED
Sorry - it seems that the code is executed after the server click event handler is executed, but before the html inside the first update panel reboots (you can simply set a breakpoint inside the server click event handler and a warning in the registered script). So, at the time of the script, the div element still contains the old html.
As a hack, you can use the setTimeout function with a small timeout (in my example, 100 ms is enough). I am looking for a suitable way to check if the html update panel is reloaded inside, and will update my response as quickly as I find it.
source share