Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Double quotes not showing up in textbox

Posted on 2006-10-30
3
Medium Priority
?
665 Views
Last Modified: 2012-08-14
I have a textbox that a user can type in anything.  If the user uses double quotes it save it fine.  When the page is brought up again anything past the double quotes is missing.  It is saved in the DB but is not shown in the textbox.  I created a hidden field and when I view source everything is there but when I change the hidden field to a textbox everything past the double quotes is missing.  Why is this and how do I prevent it from happening?
0
Comment
Question by:huerita37
3 Comments
 
LVL 54

Assisted Solution

by:Ryan Chong
Ryan Chong earned 400 total points
ID: 17839421
try use server.HTMLEncode function to encode the characters? try like:

<input name="co_name" type="text" id="co_name" value="<%=server.HTMLEncode("" & rs("co_name"))%>" size="54" maxlength="100">
0
 

Author Comment

by:huerita37
ID: 17839463
That worked but why do you need to do that?
0
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 600 total points
ID: 17840814
Hi,

The reason it worked is because the double quote character is a string delimiter in HTML. So when ASP displays the double quotes it renders it as the actual character rather than encoding it. So, for example, you have this string in a tex box:

Bob says "hi"!

You save it, everythnig is good. When the code is read back from the database it is displayed in the text box. The HTML code will receive this:

<input name="co_name" type="text" id="co_name" value="Bob says "hi"!" size="54" maxlength="100">

So, the value attribute has an oipening double quote and the string starts displaying. The string ends when it receives the second double quote. In this example, the second double quote is just before the bit that says hi. This means the string in the attribute is "Bob says " and anything afterwards is ignored which is what you're experiencing. To cure this problem you need to escape the string delimiter characters inside the text string so that the 2 double quote in my example aren't treated as string delimiters, rather they are treated as characters in the string. This is why you use the server.HTMLEncode function. What this does is covert the string within the value attribute into "safe" HTML. In this example the string is converted to:

Bob says &quot;hi&quot;!

the &quot; is what replaces the 2 double quotes. These are the HTML character codes for the double quote character. This means that when the browser renders the string, the opening double quote begins things. The string the writes to the screen, but when the browser sees the &quot; it displays a double quote and doesn't delimit the string. The string ccontinues displaying and does the same or the second &quot;. It continues until it hits the final double quote at the end of the string. This means that your string displays correctly and the browser has done it's job and everyone is happy. See http://windowssdk.msdn.microsoft.com/en-us/library/ms525347.aspx for more info. There are also HTMLDecode, URLEncode and URLDecode functions that encode and decode things for different reasons.

Regards,

Lee
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline

810 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