Solved

Double quotes not showing up in textbox

Posted on 2006-10-30
3
657 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 49

Assisted Solution

by:Ryan Chong
Ryan Chong earned 100 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 150 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Out the count variables 6 53
replace quotes with UTF-8 character 38 83
Auto Submit on dropdown box 14 51
ASP SQL Syntax Duplicate Key 7 92
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

19 Experts available now in Live!

Get 1:1 Help Now