Using an apostrophe in a textbox

Discussion in 'ASP .Net Web Controls' started by Doug, Oct 31, 2003.

  1. Doug

    Doug Guest

    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
    Doug, Oct 31, 2003
    #1
    1. Advertising

  2. Doug

    susie Guest

    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
    >.
    >
    susie, Oct 31, 2003
    #2
    1. Advertising

  3. Doug

    Doug Guest

    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
    >>.
    >>

    >.
    >
    Doug, Oct 31, 2003
    #3
  4. Doug

    vMike Guest

    You might want to look into
    HttpUtility.HtmlEncode
    and
    HttpUtility.HtmlDecode


    "Doug" <> wrote in message
    news:0bd801c39fce$bd2a2100$...
    > 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
    vMike, Oct 31, 2003
    #4
  5. Doug

    Doug Guest

    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" <> wrote in

    message
    >news:0bd801c39fce$bd2a2100$...
    >> 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

    >
    >
    >.
    >
    Doug, Oct 31, 2003
    #5
  6. Doug

    jose Guest

    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
    >.
    >
    jose, Oct 31, 2003
    #6
  7. Doug

    Doug Guest

    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
    >>.
    >>

    >.
    >
    Doug, Nov 3, 2003
    #7
  8. Doug

    Doug Guest

    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
    >.
    >
    Doug, Nov 3, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. paul reed
    Replies:
    0
    Views:
    412
    paul reed
    Oct 17, 2003
  2. Replies:
    3
    Views:
    3,351
  3. Replies:
    1
    Views:
    340
    Kevin Spencer
    Jan 19, 2005
  4. =?Utf-8?B?QnJpYW4=?=

    Apostrophe in SQL Syntax

    =?Utf-8?B?QnJpYW4=?=, Mar 7, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    7,151
    Scott Allen
    Mar 7, 2005
  5. Replies:
    5
    Views:
    619
Loading...

Share This Page