Solved

How can I allow html in textbox.

Posted on 2009-05-15
7
783 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

14 Experts available now in Live!

Get 1:1 Help Now