Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie crumbles!

Status
Not open for further replies.

raynkel

Programmer
Oct 24, 2002
23
US
I have an application that builds a Query string on the fly. I send this string to a function that builds a table on the fly from the data the Query returns. The Table string, ie..(table><tr><td>Stuff</td></tr></table>) is way too long to send in a querystring. So I have sent it to a cookie that I can recall on the next page. I can get the cookie, but it changes all my "<" to %3C and my ">" to %3E.

I tried this replace function

Dim RegX
Set RegX = NEW RegExp
Dim MyString, SearchPattern, ReplacedText
MyString = Request.Cookies("objTable")
SearchPattern = "%3C"
ReplaceString = "<"
RegX.Pattern = SearchPattern
Regx.IgnoreCase = True
RegX.Global = True
ReplacedText = RegX.Replace(MyString, ReplaceString)

but with no change to the string
this is what I get.
%3Ctable%3E%3Ctr%3E%3Ctd%3EProjectName
should be
<table><tr><td>ProjectName
any suggestions?
Thanks
Ray
 
Have you tried this ?
MyString = Replace(Request.Cookies("objTable"),"%3C","<")
ReplacedText=Replace(MyString,"%3D",">")

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PHV,
thanks you so much. I actually used

MyString = Request.Cookies("objTable")

ReplacedText=Replace(MyString,"%3E",">")

REReplacedText=Replace(ReplacedText,"%3C","<")

REREReplacedText=Replace(REReplacedText,"%2","")

For some reason the %2 showed up and I had to get rid of it too.
Thanks so much!!!
Ray
 
You don't need so many diffrerent variables:
MyString = Request.Cookies("objTable")
MyString=Replace(MyString,"%3E",">")
MyString=Replace(MyString,"%3C","<")
MyString=Replace(MyString,"%2","")

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hello raynkel,

If you familiar with escape() and unescape() in javascript/jscript, then you just have to take note that they are implemented in vbscript as well. But, this is left out in the documentation.
Code:
s="%3Ctable%3E%3Ctr%3E%3Ctd%3EProjectName"
t=unescape(s)
wscript.echo s & vbcrlf & t
regards - tsuji
 
Hmm...

It appears that you are simply trying to pass data from one page to another client-side.

As you have discovered, there are significant limitations to this technique. Length of the querystring is one. Another is that you end up exposing the workings of your pages a bit through the Address field of the browser. The latter also opens your application up to mischief through user-manipulation of the Address field.

Cookies are one way to handle this. To some extent this might get you some cross-browser compatability. It also means you have to play around with URI-encoded strings and such.


But since you are using VBScript it looks like you have accepted the idea of limiting your clients to later versions of IE anyhow. Have you considered using IE's Persistence behaviors?

Persistence lets you have 64K to 512K (depending on context) saved per page. The maximum for any domain is something like 8 to 10 times this amount.

Here is an example that uses one page called "form.htm" and another called "showme.htm" where the first has an HTML form that "submits" to the second page:

form.htm
Code:
<html>
  <head>
    <style>
      .pst {behavior: url(#default#userdata); display: none}
    </style>
    <script language=VBScript>
      Sub btnSubmit_onclick()
        divPst.setAttribute "NameValue", frmStuff.txtName.value
        divPst.setAttribute "StoryValue", frmStuff.txtStory.value
        divPst.save "frmStuffData"
        window.navigate "showme.htm"
      End Sub

      Sub window_onload()
        frmStuff.txtName.focus
      End Sub
    </script>
  </head>
  <body>
    <div id=divPst class=pst></div>
    <form id=frmStuff>
      <table border=0>
        <tr>
          <td>Your name:</td>
          <td><input type=text id=txtName size=20 maxlength=20></td>
        </tr>
        <tr>
          <td>Your story:</td>
          <td><textarea id=txtStory cols=50 rows=8></textarea></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type=button id=btnSubmit value=Submit></td>
        </tr>
      </table>
    </form>
  </body>
</html>
showme.htm
Code:
<html>
  <head>
    <style>
      .pst {behavior: url(#default#userdata); display: none}
    </style>
    <script language=VBScript>
      Sub btnShowMe_onclick()
        divPst.load "frmStuffData"
        MsgBox divPst.getAttribute("NameValue") & vbCrLf _
             & divPst.getAttribute("StoryValue")
      End Sub
    </script>
  </head>
  <body>
    <div id=divPst class=pst></div>
    <input type=button id=btnShowMe value="Show Me">
  </body>
</html>
Note that [tt]divPst[/tt] is just a convenient element I used to implement the UserData Persistence behavior on. You can pass string, numeric, and boolean data this way. I suspect that arrays and objects can't be passed like this though based upon my reading of the documentation. You'd need to serialize these items yourself first, for example by doing a Join( ) on a string array and passing the resulting value - and then Split( )ting out the array elements on the receiving side.

This is a simple example, but you can find out a lot more about Persistence in the MSDN Library.
 
Thanks for all the help everyone. I tried using the unescape, but it stripped out my <> tags leaving only table and tr showing. I may just save it to a SQL table and call it on the next page.

How would you guys do it? This is bascially a report generator. The user selects fields from the database and i create the Query and build a table from that Query. I can do it OK if I click One button to create the query and another to go to another page and show the report, just can't get it all in one click. I am using Dot Net if that helps at all.
:(

 
raynkel,

I do not get it. Are you saying you run the above demo and it stripped out the <> tags? That's not my observation. (You need vbs 5.1 upwards.)

- tsuji
 
When I used your code :
s="%3Ctable%3E%3Ctr%3E%3Ctd%3EProjectName"
t=unescape(s)
wscript.echo s & vbcrlf & t

I got an error abour the wscript

I used just the: t=unescape(s)
and it stripped oout my tags
 
raynkel,

Upgrade your script engine to v5.6. It is certainly not update enough. Run this line.
Code:
wscript.echo ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion
- tsuji
 
Sorry, thats way above my knowledge level.I am just throwing the Table tags in to a DB and calling it on the next page.
Thanks Much though
 
If you run within the asp, then it will throw an error for sure. use Msgbox at the place of wscript.echo.

If you further use response.write, the dom sure will interprete the <> tags and will not turnup in the rendering of it in the browser!

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top