Hi dccoyne67,
I just had to figure this out myself, and with Company names, so I am happy to share how I managed it.
I did get a little lost in your code so I decided to just tell you how I do it and you can apply it to your specific situation.
Disclaimer: as I have a BBA in Information Management Systems from WAY long ago, but am self-taught for ASP, this may not be the BEST way, but it worked for me. If anyone else has any better thoughts, please improve on my suggestions. Also, I'm thinking that some of the Replace functions in my code may be overkill, but after much trial and error, this is how I finally removed all the errors and surprises, so I decided to run with it. One of these days, I'll go back and see if I can "clean" it up a bit. But I'm in no rush.
In my application, about half of my pages Post back to themselves, and I access the data via request.form, and half are loaded via a hyperlink, so I access the data from request.querystring. I discovered I needed to handle these two a little differently when loading the page and the variables for access and use. I'll address both for you. Also, I use the HTML code for apostrophe in my replace.
First, to address hyperlinking and request.querystrings
Before you build your querystring to send out, any field that has a potential apostrophe in it (street names can, too, etc.), should have the Replace function run on it. You can either
1. Perform this task as the querystring is being constructed, or
2. Assign the company name to a variable first, run Replace as part of the assignment, and then use the variable in the querystring.
I do both depending on my need.
Since I pass Company IDs and Company Names a lot, I set up a variable called linkQryStrg at the beginning of those page to maximize integrity. To set that variable, I use this code:
- linkQryStrg="&qCmpID="& vCmpID&"&qCompany="&replace(vCompany,"'","'")
where the variable names with "q" are part of the querystring, and the variable names with the "v" are ASP variables being passed in.
Then, to create the hyperlink, it just looks like:
- ...<a href='frmToGoTo.asp?qAction=Add&qID="&vID&linkQryStrg tabindex=29 onclick='return chkDirty(this)'>ADD NEW ITEM</a>...
Occasionally, I only need to send the company name and in only one place on a particular page, so I don't bother with the variable assignment. I just say:
- ...<a href='frmToGoTo.asp?qAction=Add&qID="&vID&replace(vCompany,"'","'")&" tabindex=29 onclick='return chkDirty(this)'>ADD NEW ITEM</a>...
That covers creating the querystring for sending. When it gets to the destination page, use the Replace function as well when assigning the querystring value to its variable. One of my first variable assignments is always vCompany. The code is:
- vCompany=replace(request.querystring("qCompany"),"'","'")
Additionally - anywhere on the page I refer to, display, or store the variable, I also use the Replace function. (This is because I also load these particular pages as a Post and you will see later that the Replace function is not run when assigning the variable then.)
For example:
1. When stored in a Hidden text field (so it can be accessed during a Post):
- response.write("<td><input type=hidden name=txtCompName value='"&replace(vCompany,"'","'")&"'></td>"&chr(13))
OR
2. When just being displayed on the page:
- response.write("<td colspan=3 class=dealer>"&replace(vCompany,"'","'")&"</td>"&chr(13))
The only time I do not run the Replace function on the Company value is when I am assigning variables from request.form values. In that case, the code looks like:
- vCompany=request.form("txtCompName")
and the linkQryStrg is just:
- linkQryStrg="&qCmpID="&vCmpID&"&qCompany="&vCompany
But everywhere else on the page, vCompany still has the Replace function run on it as shown above.
Again, adapt this to your needs. If it is a little confusing, please let me know your questions and I will clarify. Good Luck!