Solved

How can I allow html in textbox.

Posted on 2009-05-15
7
776 Views
Last Modified: 2012-05-07
I have a database with one entry the client can change. The one entry is going to display on the front page. I want them to be able to use some html code like <b>xxx</b> or make the line of code into a link. I was trying to use just a regular text box but I can't seem to make it read the html code. I can use gridview but it's in such a tight space it pulls apart the design? Is there anyway I can make a regular label or text box read html code, or make the grid view fit in a small place?
0
Comment
Question by:designaire
  • 3
  • 3
7 Comments
 
LVL 5

Expert Comment

by:Aanvik
ID: 24400477
instead of this you should use Literal control. It should be able to handle this.


0
 
LVL 11

Accepted Solution

by:
Muhammad Ousama Ghazali earned 75 total points
ID: 24400514
TinyMCE is an excellent replacement for HTML based input into a regular textbox used at many sites including the official asp.net forums site and once started it is very easy to setup. Here is the link to its official site: http://tinymce.moxiecode.com/. If you are interested I could help you with sample code to easily setup it.
However, if you wish to acquire HTML from the simple TextBox it is not that difficult but for ASP.NET it is always a security issue. However, if you are comfortable and confident that input is from trusted users, you have to set one property of the page to false in order to let the textbox send HTML contents which may in turn contain malicious content such as script. Hence, the use of some good HTML Editors such as TinyMCE mentioned above which take care of all these problems and let you have a good programming experince while also allow users to have better looking input. TinyMCE's customization is easy and you can restrict users to use only limited formatting options by allowing only a small set of fucntions/images to appear on its toolbar.
Back to the question at hand, the property which needs to be set to False is ValidateRequest. Even though you can set it site wide from web.config it is adviseable to use it at page level only for specific pages which allow HTML input. You can do it in Page Declaration element in ASPX file. Use the sample snippet below (just copy ValidateRequest="False" part and paste it in your page):

<%@ Page ValidateRequest="False" %>

Open in new window

0
 

Author Comment

by:designaire
ID: 24400546
I'll look at the TinyMCE, especially for another page where I have more copy going into a text field.

However, the front page only has one line of type. Maybe I failed to mention it's reading from a database. I already have the Page VlidateRequiest set to false. It's fine when I'm using a GridView and it works but if I use the text box it just displays the text <b>test</b>
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:designaire
ID: 24400573
What's Literal control?
0
 
LVL 5

Assisted Solution

by:Aanvik
Aanvik earned 50 total points
ID: 24400580
0
 

Author Comment

by:designaire
ID: 24400593
When I used a Label instead of a text box to display the information from the database it worked. I'll look at both of your suggestions however. Thanks
0
 
LVL 5

Expert Comment

by:Aanvik
ID: 24400656
Label is fine for small html code.. If you need more advance then literal is best. Otherwise label is good for small text as you mentioned.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now