Solved

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

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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio hangs on running project 6 61
ASP.NET - Why is accordion not working? 3 49
auto play video on web page 4 40
Print a <div></div> only 5 39
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
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 is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

749 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