Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

932 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

8 Experts available now in Live!

Get 1:1 Help Now