Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scrolling to end of text in textbox on ASP.NET page

Status
Not open for further replies.

DaveC426913

Programmer
Jul 28, 2003
274
CA
I'm designing an ASP.NET app and I have a multiline textbox to display a running series of event messages (the same way ws_ftp does). I want the last line to be always in the window, even as the text gets longer and longer.

How can I do this? If this were a VB app, I would use Text.scrolltocaret(), but that is not an option on a webpage textbox control.

I am also open to suggestions about how I can display these messages to the user in some other format (such as a different control.) It would be nice to be able to insert some rich text in my messages, such as colour or bolding on specific lines.
 
On the server you can use:
Place a literal control add the very end of the HTML page but within the <Form></FORM> tags.

The literal has an id of "MyLiteral"

MyLiteral.Text = "<script>window.setTimeout(""document.getElementById('" & MyTextArea.ClientID & "').scrollTop=10000"",500)</script>"

10000 is just a high number so the textarea scrolls to the end. If it is very large then use a higher number.
 
That's a whole lot of quote marks in there...

I've gotten this far:

<script language="javascript">
document.frmShowPP.MyLiteral.Text=window.setTimeout("document.getElementById('" & lblStatus.ClientID & "').scrollTop=10000",500)
</script>
...
<asp:Label ID="MyLiteral" Text="" />
Can't get it to recognize MyLiteral in the JavaScript.
 
Got it. This works:

<script language="javascript">
document.frmShowPP.MyLiteral.Text=window.setTimeout("document.frmShowPP.lblStatus.scrollTop=10000",500)
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top