Solved

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

Posted on 2009-07-07
3
281 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

778 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