0

I have a large amount of text data that I want to display in something like a HTML.TextAreaFor(). I tried this using the readonly html property. However, the user can still select the date and click into the box. It's confusing for the user. Is there another control I can use or are ther other attrubutes of the HTML.TextAreaFor() that I can use to make it look un-edittable.

@Html.TextArea("SOWDescription", Model.SowDescription,
     new { rows = 5, cols = 50, @class = "celltext2", @readonly="true" })

TextAreaFor enter image description here

MikeTWebb
  • 9,149
  • 25
  • 93
  • 132

2 Answers2

5

You could just put it in something like a div and allow it to scroll using css:

<div style="height: 300px; overflow: scroll;">@Model.SowDescription</div>
twaggs
  • 3,591
  • 1
  • 14
  • 8
  • @twaggs...cool, what are the CSS properties I would use. I'm new to MVC3 – MikeTWebb Nov 15 '11 at 23:06
  • @MikeTWebb I updated his answer to show the css, the most important part obviously is `overflow: scroll` – Paul Tyng Nov 15 '11 at 23:08
  • You'll want to set the width and height on the containing element (div in the example) and see overflow: http://www.w3schools.com/cssref/pr_pos_overflow.asp – twaggs Nov 15 '11 at 23:10
  • If you only want it to scroll in one direction you can independently restrict overflow for x/y (ie. `overflow-y: scroll` for only vertical scrolling) – Paul Tyng Nov 15 '11 at 23:14
  • @Twaggs....that's great info...but, kind of the same issue as the TextAreaFor. The user can click into the div and highlight text even though they can't edit it...hmmmmm. Ideas? – MikeTWebb Nov 15 '11 at 23:14
  • See this SO question for how to disable selection highlighting: http://stackoverflow.com/questions/826782/css-rule-to-disable-text-selection-highlighting you can add those inline in that `style` attribute on the DIV, or use a class and apply it to any divs like this. – Paul Tyng Nov 15 '11 at 23:16
  • What Paul said. I'm new to SO, should I edit the answer with the additional styles for disabling selection? – twaggs Nov 15 '11 at 23:19
  • @Paul...Visual Studio is saying that user-select: is no longer available in CSS 3.0. Any ideas on what the alternative would be? – MikeTWebb Nov 15 '11 at 23:29
0

I used the "unselectable" attribute. And it does invalidate the HTML. In CSS 3.0, this is the only way to dis-allow selecting text.

See: CSS 3.0 user-select property replacement

Community
  • 1
  • 1
MikeTWebb
  • 9,149
  • 25
  • 93
  • 132