Just a quick little tip I came across while trying to figure out how to render HTML into a scrollable textbox. Originally I wanted to create a Terms & Conditions scroll box, nothing special here.
What was driving me nuts was the encoding. I had created an ASP.NET textbox, set it to multi-line and set the text to it from code-behind.
I’m tired of using ASP.NET controls, especially when you can do something like this much easier with plain HTML and CSS and it’s working just fine cross browswer and always will. And as I’ve worked a bit in MVC on a team, I move away more and more from ASP.NET controls when I still work in some classic ASP.NET environments also in mark-up. You absolutely don’t even need those controls at all in ASP.NET. So decided to switch to a div after finding out that you can just do this with a div like so:
<div id="divTerms" class="scrollableDiv-500x130" runat="server">
Here’s the class (note that this won’t work with an id..as you know you can use for styling also):
.scrollableDiv-500x130
{
width: 500px;
height: 130px;
overflow: auto;
}
Now the ASP.NET part of it in terms of setting the text from code-behind:
private void SetTermsText()
{
StringBuilder termsText = new StringBuilder();
termsText.AppendFormat(@"<p class=""bold_black_12"">Some text here..</p>");
termsText.AppendFormat(@"<p>some more formatted text...</p>");
divTerms.InnerHtml = termsText.ToString();
}
Print | posted on Monday, October 19, 2009 9:02 PM