How to scroll asp.net text box

I am creating a website with a text box containing log messages. The journal is updated using AJAX.

<asp:UpdatePanel ID="UpdatePanel1" runat="server" > <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" onload="textbox_load" Height="110px" TextMode="MultiLine" Width="100%"> </asp:TextBox> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> </asp:UpdatePanel> 

I need to scroll the text box every time it is updated. How?

0
source share
3 answers

Handle the Sys.WebForms.PageRequestManager.endRequest event and scroll down the text box:

 var tbox = $get('<%= TextBox1.ClientID %>'); tbox.tbox.scrollTop = tbox.scrollHeight; 
+3
source

Try simple javascript. Here is an example that I think you can change to work in your scenario:

 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function scrollDown() { document.getElementById('<%=TextBox1.ClientID%>').scrollTop = document.getElementById('<%=TextBox1.ClientID%>').scrollHeight; }; </script> </head> <body> <form id="form1" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </form> </body> </html> 

You just need to figure out how to call the scrollDown method ...

0
source

Why don't you try this simple example:

protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {

  Page.ClientScript.RegisterStartupScript(this.GetType(), "ScrollTextbox", "<script type=\"text/javascript\">document.getElementById('" + this.TextBox1.ClientID + "').scrollTop = document.getElementById('" + this.TextBox1.ClientID + "').scrollHeight; " + " </script>"); } } 

Just change the TextBox1 parameter with your text field name. You can see that the content in the text box scrolls from the bottom.

You can call this java script after AJAX updates the contents of your text field.

0
source

Source: https://habr.com/ru/post/1277467/


All Articles