Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Using an apostrophe in a textbox

Reply
Thread Tools

Using an apostrophe in a textbox

 
 
Doug
Guest
Posts: n/a
 
      10-31-2003
I am creating an ASP.Net application that has a textbox
populated with a store name field from a SQL Server
database. I need to allow the user to change the name
string, and update the database. In several instances,
the name will contain an apostrophe (i.e. Macy's). In
the code behind, using the assignment: str =
textbox.text, the variable will contain the string
(Macys) without the apostrophe. How do I get the
apostrophe to show up? Thanks.

Doug
 
Reply With Quote
 
 
 
 
susie
Guest
Posts: n/a
 
      10-31-2003
Use string manipulation functions
'---
Sub ChangeBox( s As Object, e As EventArgs )
Dim a As String = txtBox.Text
Dim b As String
dim c as String
dim d as String
b = right(a, 1)
c=left(a,len(a)-1)
d=c+"'"+b
txtBox.Text=d
End Sub

'---------
<asp:TextBox
ID="txtBox"
AutoPostBack="True"
onTextChanged="ChangeBox"
Runat="Server"/>

The above code should work. You will need to change to
datasource for the textbox if it is populated from SQL
server.

Good luck.
>-----Original Message-----
>I am creating an ASP.Net application that has a textbox
>populated with a store name field from a SQL Server
>database. I need to allow the user to change the name
>string, and update the database. In several instances,
>the name will contain an apostrophe (i.e. Macy's). In
>the code behind, using the assignment: str =
>textbox.text, the variable will contain the string
>(Macys) without the apostrophe. How do I get the
>apostrophe to show up? Thanks.
>
>Doug
>.
>

 
Reply With Quote
 
 
 
 
Doug
Guest
Posts: n/a
 
      10-31-2003
Thanks for the reply. That will work for the case I
mentioned, but there are other scenarios that are
different: A'Chen, Frank's Foods, Linens 'N Things, etc.
I cannot know how the users are going to want the store
names displayed, so I must be able to replicate an
apostrophe at any position in the string.

>-----Original Message-----
>Use string manipulation functions
>'---
>Sub ChangeBox( s As Object, e As EventArgs )
>Dim a As String = txtBox.Text
>Dim b As String
>dim c as String
>dim d as String
>b = right(a, 1)
>c=left(a,len(a)-1)
>d=c+"'"+b
>txtBox.Text=d
>End Sub
>
>'---------
><asp:TextBox
> ID="txtBox"
> AutoPostBack="True"
> onTextChanged="ChangeBox"
> Runat="Server"/>
>
>The above code should work. You will need to change to
>datasource for the textbox if it is populated from SQL
>server.
>
>Good luck.
>>-----Original Message-----
>>I am creating an ASP.Net application that has a textbox
>>populated with a store name field from a SQL Server
>>database. I need to allow the user to change the name
>>string, and update the database. In several instances,
>>the name will contain an apostrophe (i.e. Macy's). In
>>the code behind, using the assignment: str =
>>textbox.text, the variable will contain the string
>>(Macys) without the apostrophe. How do I get the
>>apostrophe to show up? Thanks.
>>
>>Doug
>>.
>>

>.
>

 
Reply With Quote
 
vMike
Guest
Posts: n/a
 
      10-31-2003
You might want to look into
HttpUtility.HtmlEncode
and
HttpUtility.HtmlDecode


"Doug" <(E-Mail Removed)> wrote in message
news:0bd801c39fce$bd2a2100$(E-Mail Removed)...
> I am creating an ASP.Net application that has a textbox
> populated with a store name field from a SQL Server
> database. I need to allow the user to change the name
> string, and update the database. In several instances,
> the name will contain an apostrophe (i.e. Macy's). In
> the code behind, using the assignment: str =
> textbox.text, the variable will contain the string
> (Macys) without the apostrophe. How do I get the
> apostrophe to show up? Thanks.
>
> Doug



 
Reply With Quote
 
Doug
Guest
Posts: n/a
 
      10-31-2003
I looked at that but don't see how that is going to
help. Somehow I am losing the apostrophe between the
textbox and the code behind .vb page. It is missing in
the locals window for textbox.text as soon as it comes up
there. If I type in 2 apostrophes they show up in locals.

>-----Original Message-----
>You might want to look into
>HttpUtility.HtmlEncode
>and
>HttpUtility.HtmlDecode
>
>
>"Doug" <(E-Mail Removed)> wrote in

message
>news:0bd801c39fce$bd2a2100$(E-Mail Removed)...
>> I am creating an ASP.Net application that has a textbox
>> populated with a store name field from a SQL Server
>> database. I need to allow the user to change the name
>> string, and update the database. In several instances,
>> the name will contain an apostrophe (i.e. Macy's). In
>> the code behind, using the assignment: str =
>> textbox.text, the variable will contain the string
>> (Macys) without the apostrophe. How do I get the
>> apostrophe to show up? Thanks.
>>
>> Doug

>
>
>.
>

 
Reply With Quote
 
jose
Guest
Posts: n/a
 
      10-31-2003
so after assignment, str has Macys
without the apostrophe?
when debugging, does textbox.text contain the apostrophe?
I don't know if this will work for your case but I had
a somewhat similar problem when trying to update a text
field in a MS Access table. Access was reading the
apostrophe as a single quote and generating an error.
I used something like this to "double-up" the single quote.
string str = textbox.text.Replace("'", "''");


>-----Original Message-----
>I am creating an ASP.Net application that has a textbox
>populated with a store name field from a SQL Server
>database. I need to allow the user to change the name
>string, and update the database. In several instances,
>the name will contain an apostrophe (i.e. Macy's). In
>the code behind, using the assignment: str =
>textbox.text, the variable will contain the string
>(Macys) without the apostrophe. How do I get the
>apostrophe to show up? Thanks.
>
>Doug
>.
>

 
Reply With Quote
 
Doug
Guest
Posts: n/a
 
      11-03-2003
The apostrophe exists in the textbox, but does not in
debugging when it will be assigned to a variable. I had
written almost that exact code to double up the
apostrophe to add to my update query, but without the
first apostrophe, I can't get a second one. Weird...

>-----Original Message-----
>so after assignment, str has Macys
>without the apostrophe?
>when debugging, does textbox.text contain the apostrophe?
>I don't know if this will work for your case but I had
>a somewhat similar problem when trying to update a text
>field in a MS Access table. Access was reading the
>apostrophe as a single quote and generating an error.
>I used something like this to "double-up" the single

quote.
>string str = textbox.text.Replace("'", "''");
>
>
>>-----Original Message-----
>>I am creating an ASP.Net application that has a textbox
>>populated with a store name field from a SQL Server
>>database. I need to allow the user to change the name
>>string, and update the database. In several instances,
>>the name will contain an apostrophe (i.e. Macy's). In
>>the code behind, using the assignment: str =
>>textbox.text, the variable will contain the string
>>(Macys) without the apostrophe. How do I get the
>>apostrophe to show up? Thanks.
>>
>>Doug
>>.
>>

>.
>

 
Reply With Quote
 
Doug
Guest
Posts: n/a
 
      11-03-2003
It looks like either the page or project has become
corrupt. If I duplicate the functionality in a new
project, it works fine. Thanks for everyone's input.

Doug

>-----Original Message-----
>I am creating an ASP.Net application that has a textbox
>populated with a store name field from a SQL Server
>database. I need to allow the user to change the name
>string, and update the database. In several instances,
>the name will contain an apostrophe (i.e. Macy's). In
>the code behind, using the assignment: str =
>textbox.text, the variable will contain the string
>(Macys) without the apostrophe. How do I get the
>apostrophe to show up? Thanks.
>
>Doug
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need validation to fail on an apostrophe entered into a textbox for my regularexpression validator hamsterchaos@gmail.com ASP .Net 5 11-05-2007 10:48 PM
Firebird bug? Message board using apostrophe gives search popup etc nospam4me Firefox 1 05-27-2005 08:34 AM
apostrophe in parameterised SP call trouble spacehopper_man@yahoo.com ASP .Net 3 01-20-2005 11:00 AM
apostrophe in parameterised SP call trouble spacehopper_man@yahoo.com ASP .Net 1 01-19-2005 09:36 PM
Re: How to keep apostrophe in string with jscript paul reed ASP .Net 0 10-17-2003 03:31 AM



Advertisments