简体   繁体   中英

ASP.net textbox scrolling when disabled

Greetings, I have a form where employees enter comments in a multiline textbox with a limit of 4000 characters. I have the rows set to 8 (obviously an arbitrary number).

When a supervisor looks at the comments the textbox is disabled so the employee comments cannot be modified.

The problem is when the data extends below row 8. Since the textbox is disabled the scrollbar cannot be moved and the supervisor cannot see all the comments. If I hide the textbox and databind to a label for the supervisor none of the line breaks are maintained and a well written paragraph turns into the biggest run on sentence ever…

Is there a way to enable the scroll bar leaving the text disabled?
Is there a way to preserve the structure of the entry in the label?

Instead of disabling the textbox you should set the ReadOnly property to True. This keeps the scrollbars functional but doesn't allow modification of the textbox.

txtComments.ReadOnly = true;

In supervisor mode, don't put the text into a textbox, put it in a label as you mentioned, with '.Replace("\\n", "<br>")' in your code.

Alternatively, show the textbox without disabling it, and just disable the 'save' button. Put a note on the page saying that, "changes made here are not persistent" or something to that effect.

使文本框为只读,并将前景颜色设置为禁用文本框中使用的相同灰度。

<asp:TextBox ForeColor="#AFAFAF" ReadOnly="true" />

Put the text in a PRE tag, and apply overflow:scroll to it.

Make sure to escape the text using Server.HtmlEncode first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM