473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Dynamic creation of ASP code



Hi all,

I am trying to generate ASP code on the fly as I want to be able to
control
the code from the database and am running a problem.

When I try this (simplified example of what I have but it conveys the
problem):

<%
replacetext = "response.write ""blah"""
response.write "<%" & replacetext & "%\>"
%>

I get an empty page with <%response.write "blah"%> in the source instead
of
what I want: a page that has 'blah' on it.

Is there any trick behind this?

thanks
Arne

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #1
11 1647
"Arne de Booij" wrote:

replacetext = "response.write ""blah"""
response.write "<%" & replacetext & "%\>"

I get an empty page with <%response.write "blah"%> in the source
instead of what I want: a page that has 'blah' on it.

Is there any trick behind this?


1. What's wrong with just doing this?

Response.Write("""blah""")

-or-

replacetext = """blah"""
Response.Write(replacetext)

-or-

replacetext = """blah"""
...
<%=replacetext%>
2. I was unaware you could use \ to escape characters in VBScript.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #2
Perhaps you need to explain more what you require.
The asp parser just isnt going to run twice...
"Arne de Booij" <a_********@hotmail.com> wrote in message
news:Ou**************@TK2MSFTNGP09.phx.gbl...


Hi all,

I am trying to generate ASP code on the fly as I want to be able to
control
the code from the database and am running a problem.

When I try this (simplified example of what I have but it conveys the
problem):

<%
replacetext = "response.write ""blah"""
response.write "<%" & replacetext & "%\>"
%>

I get an empty page with <%response.write "blah"%> in the source instead
of
what I want: a page that has 'blah' on it.

Is there any trick behind this?

thanks
Arne

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #3
You just write some text (that happens to be "ASP code") to the browser
exacly as if it were HTML code. You have actually to execute the code (using
perhaps "Execute" if I remember) rather than just writing the code to the
browser.

That said, I would still double check this design. Do you mean you want to
store the ASP code inside the DB ? What is the overall goal (expected
benefit) ?

Patrice

"Arne de Booij" <a_********@hotmail.com> a écrit dans le message de
news:Ou**************@TK2MSFTNGP09.phx.gbl...


Hi all,

I am trying to generate ASP code on the fly as I want to be able to
control
the code from the database and am running a problem.

When I try this (simplified example of what I have but it conveys the
problem):

<%
replacetext = "response.write ""blah"""
response.write "<%" & replacetext & "%\>"
%>

I get an empty page with <%response.write "blah"%> in the source instead
of
what I want: a page that has 'blah' on it.

Is there any trick behind this?

thanks
Arne

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #4

"Arne de Booij" <a_********@hotmail.com> schrieb im Newsbeitrag
news:Ou**************@TK2MSFTNGP09.phx.gbl...


Hi all,

I am trying to generate ASP code on the fly as I want to be able to
control
the code from the database and am running a problem.

When I try this (simplified example of what I have but it conveys the
problem):

<%
replacetext = "response.write ""blah"""
response.write "<%" & replacetext & "%\>"
%>

I get an empty page with <%response.write "blah"%> in the source instead
of
what I want: a page that has 'blah' on it.

Is there any trick behind this?

thanks
Arne

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


This example should work for your purpose:

<%
replacetext = "response.Write ""blah"""
execute replacetext
%>

The Response.Write - Command only dumps the text you give him to the client.
The Execute - Command actually executes the lines in the string and in this
way only returns "blah" to the client.

You can also chain several commands with the ":" - Character

for Example:

<%
StrTemp = "strEcho = ""Just Testing<br>"" & vbcrlf :" & _
" Response.Write ""Hello World.<br>"" & vbcrlf :" & _
" For iTmp = 1 to 4 : Response.Write strEcho : Next"

execute strTemp
%>

(I have seen this on one of these .vbs worms that travelled around the globe
some months ago and tried it in asp...)

HTH
Gottfried
Jul 19 '05 #5
PW

"Dave Anderson" <GT**********@spammotel.com> wrote in message
news:40***********************@newsreader.visi.com ...

2. I was unaware you could use \ to escape characters in VBScript.

How do you do it ?
I was trying to send a chr(7) BEL character to a receipt printer, but
couldn't figure it out.

Jul 19 '05 #6


In reply to "1. What's wrong with just doing this?"

I might have oversimplyfied the example.

What I am trying to do is:
1. I have a flat text string (strSentence)
2. I want to replace certain parts of the string

I wrote some ASP code that automatically generated the ASP code I
wanted. For example, if I wanted to replace every 'Yes' and 'No' in
'strSentence' then it would generate

replace(replace(strSentence, "Yes", "<b>Yes</b>"), "No", "<i>No</i>))

I then want to display the result of this code ('<b>Yes</b>'), not the
code itself. And strSentence is dynamic and I want to be able to add
'replacements' through the DB, just writing down the code is not an
option.

Maybe I am approaching the problem wrongly and is there a much easier
way of doing this.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #7
> How do you do it ?
I was trying to send a chr(7) BEL character to a receipt printer, but
couldn't figure it out.


What did you try?

Response.Write "Str" & Chr(7) & "Str"

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #8
> I wrote some ASP code that automatically generated the ASP code

Why? If you're storing this in a database, you can't easily make ASP
suddenly parse and execute twice... this is not how ASP works.

You can use the execute command in VBScript, but as Michael Kersey will
surely echo, there are serious security implications involved.

--
http://www.aspfaq.com/
(Reverse address to reply.)
Jul 19 '05 #9
Youl'l have just to store the match and replacement string in the db. Your
code will act on these data as usual when it comes to using a DB.

It could give something like :

Set rst=GetRecordset("SELECT Match,Replacement FROM StringTable")
Do While Not rst.Eof

strSentence=Replace(strSentence,rst("Match").Value ,rst("Replacement").Value)
rst.MoveNext
Loop
rst.Close
Response.Write strSentence.

You could wrap all this in a function so that you act or whatever sentence
you passed. Of course you could cache the strings in a an array or
something.

You could also create a regular expression that does this job (you'll likely
have some problems with "snow" giving "s<i>No</i>w", a regular exp could
avoid this).
Patrice

"Arne de Booij" <a_********@hotmail.com> a écrit dans le message de
news:eO**************@TK2MSFTNGP09.phx.gbl...


In reply to "1. What's wrong with just doing this?"

I might have oversimplyfied the example.

What I am trying to do is:
1. I have a flat text string (strSentence)
2. I want to replace certain parts of the string

I wrote some ASP code that automatically generated the ASP code I
wanted. For example, if I wanted to replace every 'Yes' and 'No' in
'strSentence' then it would generate

replace(replace(strSentence, "Yes", "<b>Yes</b>"), "No", "<i>No</i>))

I then want to display the result of this code ('<b>Yes</b>'), not the
code itself. And strSentence is dynamic and I want to be able to add
'replacements' through the DB, just writing down the code is not an
option.

Maybe I am approaching the problem wrongly and is there a much easier
way of doing this.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #10
http://www.aspfaq.com/2344

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Patrice" <no****@nowhere.com> wrote in message
news:eU*************@TK2MSFTNGP11.phx.gbl...
Youl'l have just to store the match and replacement string in the db. Your
code will act on these data as usual when it comes to using a DB.

It could give something like :

Set rst=GetRecordset("SELECT Match,Replacement FROM StringTable")
Do While Not rst.Eof

strSentence=Replace(strSentence,rst("Match").Value ,rst("Replacement").Value) rst.MoveNext
Loop
rst.Close
Response.Write strSentence.

You could wrap all this in a function so that you act or whatever sentence
you passed. Of course you could cache the strings in a an array or
something.

You could also create a regular expression that does this job (you'll likely have some problems with "snow" giving "s<i>No</i>w", a regular exp could
avoid this).
Patrice

"Arne de Booij" <a_********@hotmail.com> a écrit dans le message de
news:eO**************@TK2MSFTNGP09.phx.gbl...


In reply to "1. What's wrong with just doing this?"

I might have oversimplyfied the example.

What I am trying to do is:
1. I have a flat text string (strSentence)
2. I want to replace certain parts of the string

I wrote some ASP code that automatically generated the ASP code I
wanted. For example, if I wanted to replace every 'Yes' and 'No' in
'strSentence' then it would generate

replace(replace(strSentence, "Yes", "<b>Yes</b>"), "No", "<i>No</i>))

I then want to display the result of this code ('<b>Yes</b>'), not the
code itself. And strSentence is dynamic and I want to be able to add
'replacements' through the DB, just writing down the code is not an
option.

Maybe I am approaching the problem wrongly and is there a much easier
way of doing this.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Jul 19 '05 #11

thank you all for your replies! I am going with Patrice's suggestion.

I didn't know about this (see below) before but now I do. Thanks Aaron!

If you're storing this in a database, you can't easily make ASP suddenly
parse and execute twice... this is not how ASP works.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eddie de Bear | last post by:
Hi, A project I am working on has a requirement for dynamic menus. For the most part this works really well. The menus I'm creating a based on files and directories, so naturally the menu...
5
by: Tompa | last post by:
Hi, I would like to create images on the fly as a response to an http request. I can do this with PIL like this (file create_gif.py): from PIL import Image, ImageDraw print 'Status: 200 OK'...
2
by: JC | last post by:
Hello, I'm looking for examples of how to make dynamic creation of code and dynamic execution of the same code. I want to do some code dynamically and then I want to use it to get some results....
1
by: andrew queisser | last post by:
I've been trying to dynamically create a class DevT that's derived from a generic base GenBase<T>. It doesn't seem to work. I'm attaching a code sample below that illustrates the problem. ...
2
by: charliewest | last post by:
I need to create textboxes in real-time, the actual number of which is determine by a result from a database query. I have been able to create the controls, and then add them to the ASPX page....
15
by: rwf_20 | last post by:
I just wanted to throw this up here in case anyone smarter than me has a suggestion/workaround: Problem: I have a classic producer/consumer system which accepts 'commands' from a socket and...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
13
by: xian_hong2046 | last post by:
Hello, I think dynamic memory allocation is supposed to be used when one doesn't know in advance how much memory to allocate until run time. An example from Thinking in C++ is to dynamically...
13
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his...
1
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.