|
-
Sep 11th, 2003, 04:07 AM
#1
Thread Starter
Member
response.write
with respect to my earlier query
say,
I have a string
a = "<% response.write('UHMNC') %>"
now i want to print it to get the state ment
My Id is UHMNC '''''expected output
hence in code i use
response.write("My Id is " & a) '''''code used
but the out put i get is
My Id is '''''output
and the html source shows
My Id is <% response.write('UHMNC') %> '''''html source
I cannot understand why
<% response.write('UHMNC') %>
is not executed to give me
UHMNC.
Any One Could Please Help.
-
Sep 11th, 2003, 06:10 AM
#2
Frenzied Member
I think you are getting a bit confused.
If you have a string called a and you wish to output it to the screen you need to do the following:
<%
a = "UHMNC"
%>
<%= a %>
OR
<%
a = "UHMNC"
esponse.Write(a)
%>
If this is not clear or if I have misunderstood please message back.
DJ
-
Sep 11th, 2003, 12:34 PM
#3
Thread Starter
Member
clarification
thanks for your interest
As stated My string which is assigned to a variable a is as follows
<%
a = "<% response.write('UHMNC') %>"
%>
Please do not misunderstand it as
a="uhmnc"
Tha "<%" and "%>" both are a part of the string and not the asp delimiters.
-
Sep 11th, 2003, 12:42 PM
#4
Frenzied Member
Re: response.write
Originally posted by uhmnc
I cannot understand why
<% response.write('UHMNC') %>
is not executed to give me
UHMNC.
Here is why:
Server executes ASP (VBScript) on the server side first and sends it back to your browser as ready html document.
So, when you are saying
a = "<% response.write('UHMNC') %>"
response.write a
It is gonna write exact string <% response.write('UHMNC') %> on the page, but it is not gonna be executed as a code on the server side.
I hope I was clear enought.
-
Sep 11th, 2003, 03:30 PM
#5
Frenzied Member
Yes you are right. But why do you need the <% Response.write(' ') %> in the string at all?
-
Sep 12th, 2003, 10:02 AM
#6
Thread Starter
Member
thanks but........
Is'nt there any method by which i can execute the string on the asp page.
basicall i am creating a module where by begginers can enter the basic asp syntax in a text field and can see the same being executed.
hence if the user inputs <% response.write('UHMNC') %>
and hence the mentioned problem..
Hope u will suggest a suitable method for this to be done
-
Sep 12th, 2003, 10:06 AM
#7
Frenzied Member
Ah right I can see why you have that within the string now.
Off the top of my head I can't think of a way of doing it - but I'll have a look around.
Isn't what you are suggesting a tad dangerous - if a user can just enter code onto a page and have it run server-side they could do no end of damage.
-
Sep 12th, 2003, 04:52 PM
#8
Frenzied Member
There is a way to do it.
Use FSO (File System Object) to create ASP file, save it on server and execute it after using
server.execute "path/to/saved/file.asp"
It's only way to do it.
-
Sep 12th, 2003, 05:45 PM
#9
Frenzied Member
Here is an example. You may need change path. I creating file in 'db' folder on wwwroot. Make sure you have read-write permiossions to this folder.
Code:
<html>
<head>
<title>Type your ASP code here</title>
</head>
<%
Dim fso
Dim fso_file, act
Dim fso_stream
Dim mycode
Dim fileName
act=request("act")
if len(act)<>0 then
mycode=request.form("code")
fileName="codetest.asp"
filePath=server.mappath("/db/") & "\" & fileName
set fso=server.createobject("Scripting.FileSystemObject")
fso.CreateTextFile(filePath)
set fso_file=fso.GetFile(filePath)
set fso_stream=fso_file.OpenAsTextStream(2)
fso_stream.write "<html><head><title>Code Execute</title></head><body>" & _
mycode & _
"</body></html>"
fso_stream.close
response.write "Result:<hr><span style='background:#E4E4E4'>"
server.execute "../db/" & fileName
response.write "</span><hr><br>"
fso_file.delete true
set fso_file=nothing
set fso_stream=nothing
set fso=nothing
end if
%>
<body>
Type your ASP code here:
<form method="POST" action="code.asp?act=1">
<textarea name="code" rows="17" cols="89"></textarea><br>
<input type="submit" value="Execute Code" name="exec">
</form>
</body>
</html>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|