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.
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. [quoted text, click to view] >-----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 >.
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. [quoted text, click to view] >-----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 >>. >> >.
You might want to look into HttpUtility.HtmlEncode and HttpUtility.HtmlDecode [quoted text, click to view] "Doug" <anonymous@discussions.microsoft.com> wrote in message news:0bd801c39fce$bd2a2100$a501280a@phx.gbl... > 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
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. [quoted text, click to view] >-----Original Message----- >You might want to look into >HttpUtility.HtmlEncode >and >HttpUtility.HtmlDecode > > >"Doug" <anonymous@discussions.microsoft.com> wrote in message >news:0bd801c39fce$bd2a2100$a501280a@phx.gbl... >> 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 > > >.
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("'", "''"); [quoted text, click to view] >-----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 >.
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... [quoted text, click to view] >-----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 >>. >> >.
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 [quoted text, click to view] >-----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 >.
Don't see what you're looking for? Try a search.
|