Results 1 to 9 of 9

Thread: response.write

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    60

    Question 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.

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    60

    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.

  4. #4
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615

    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.
    Visit my PROJECTS @ www.asprojects.com

  5. #5
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    Yes you are right. But why do you need the <% Response.write(' ') %> in the string at all?

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    60

    Unhappy 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

  7. #7
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    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.

  8. #8
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    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.
    Visit my PROJECTS @ www.asprojects.com

  9. #9
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    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>
    Visit my PROJECTS @ www.asprojects.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width