Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to save submit .net control containing script/html contents

Posted on 2009-07-07
3
282 Views
Last Modified: 2013-11-07
How can I save string data from a .net html control into a database using the stock html controls (textbox, textarea, etc)?  The controls error out when I submit the page and the contents of the control contain html markup ( <br> tags, etc.).  Ideally, I would like to be able to craft and save and HTML form and associated input controls from a webpage using a textarea or something like that. I understand why .NET does not allow this by default (for good reason), but is there a way around it using just stock .NET html controls. If not, does anyone know of a third party control (such as freetextbox) that can be made to allow this?

using asp.net 1.1

Thanks!
0
Comment
Question by:jkwasson
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 500 total points
ID: 24802181
Hi,

I would suggest using "Server.HtmlEncode(YourInputString)" when inserting it into the database. This will convert the < > and other characters into the html equivalents such as &lt, &gt etc. Then, when retrieving the data from the database, simply do a Server.HtmlDecode(YourInputString) to convert the characters back.

/Carl.
0
 
LVL 5

Author Comment

by:jkwasson
ID: 24805110
Thanks. I also found the page directive ValidateRequest, which will disable the checking for script in a submitted control. I think that, along with my own validation and the htmlencode you mentioned is going to work. Thanks for your help!
0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 24805706
Hi,

I would not recommend disabling ValidateRequest as there are methods that allow you to perform this without turning off the request validation. Good luck with Your project!

/Carl.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
This video teaches users how to migrate an existing Wordpress website to a new domain.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

861 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