Solved

How can I allow html in textbox.

Posted on 2009-05-15
7
785 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Executing SSIS with a Stored Procedure Permissions 12 56
Crystal reports vb.net 2 39
SQL LINE CONTINUATION ISSUE 12 31
Please explain the parts of these 2 LINQ expressions 3 26
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

813 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

10 Experts available now in Live!

Get 1:1 Help Now