Forums

ASP

This topic is locked

mixing asp and javascript????

Posted 14 Dec 2002 02:42:45
1
has voted
14 Dec 2002 02:42:45 suhail kaleem posted:
hi !
how do i equal the js variable value to the asp variable value ?

var pagehtml="<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; " +
"charset=windows-1252\">\n<meta name=\"GENERATOR\" content=\"PageCreate\">\n" +
"<title>New Page</title>\n</head>\n<body> <br> <br> <%=session("varbody"%>" +
" <br> \n</body>\n</html>";


now if the session("varbody" conatins " or any other js iligal character it will produce a error in js script like line feeds/line breaks so how do i fix it ?

Thnaks
suhailkaleem


Replies

Replied 14 Dec 2002 07:54:57
14 Dec 2002 07:54:57 Owen Eastwick replied:
Ouch!

You're using a session variable to store the whole of the page body?

A session variable uses a portion of the servers RAM to store information, so if you store a large amount of information in a session variable, like a whole page which is likely to be equivalent to a couple of Mb or more you will be taking this amount for each and every user using the site.

So, lets say you are storing 5Mb of info in a session variable and there are 100 people using the site, that's 500Mb of the servers RAM you are using. As you can see, at this rate, you will quickly use up all the available RAM on the server and the performace of your web site will be terrible. If you are on a shared server, all the sites on that server will take a performance hit.

Session variables should be used with caution and only to store small amounts of data, like a username, which only takes up a few bytes.

Reference: msdn.microsoft.com/library/default.asp?url=/library/en-us/dnasp/html/asptips.asp

In answer to your question, single quotes are valid HTML. e.g.

varHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'>"

<%= varHTML %>

Regards

Owen.

Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Replied 14 Dec 2002 17:39:27
14 Dec 2002 17:39:27 suhail kaleem replied:
hi
Thanks for the info !
but what i am trying to do is to make asp fucntion that will completely convert HTML TO JAVASCRIPT
here is what i came up with but still there are errors
<pre id=code><font face=courier size=2 id=code>
&lt;html&gt;
&lt;body&gt;

&lt;%
if request.form &lt;&gt; "" then
vart=replace(request.form("S1","""" ,"\"""
vart= replace (vart,"/","//"
vart= replace (vart,Chr(13),"\n"
vart= replace (vart,Chr(10),"\n"
response.write vart
response.write "&lt;p&gt;&lt;textarea rows=""4"" name=""S1"" cols=""22""&gt;"&vart&"&lt;/textarea&gt;&lt;/p&gt;"
end if
%&gt;
&lt;script language="JavaScript"&gt;
&lt;!--

var pagehtml="&lt;%=vart%&gt;";

document.writeln(pagehtml);
document.writeln(" &lt;p&gt;&lt;textarea rows=\"4\" name=\"S1\" cols=\"22\"&gt;"+pagehtml+"&lt;//textarea&gt;&lt;//p&gt;";


--&gt;

&lt;/script&gt;

&lt;form method="POST"&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;textarea rows="4" name="S1" cols="22"&gt;&lt;/textarea&gt;&lt;/p&gt;
&lt;p&gt;&lt;input type="submit" value="Submit" name="B1"&gt;&lt;input type="reset" value="Reset" name="B2"&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/form&gt;



&lt;/body&gt;

&lt;/html&gt;
</font id=code></pre id=code>

let me know if i ma going in teh write direction
Thanks



Edited by - suhailkaleem on 14 Dec 2002 17:46:34

Reply to this topic