By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,960 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,960 IT Pros & Developers. It's quick & easy.

Execute a string of code as if it were a page

P: n/a
Hi,

I wondering if it is possible in asp.net to somehow execute a string
of code as if it were a page on the server. That is to say, if I
executed the following code which resided in an aspx page

<html>
<body>
<% Response.Write("Hi.") %>
</body>
</html>

the output would be

<html>
<body>
Hi
</body>
</html>

Is there some way I could execute the asp.net from above without it
being in an actual page? Can I send some server method a string and
get the output?

Thanks for any help,

Nick
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
TJS
build the string , populate it with dynamic content and use,
response.write("mystring")

"nick" <ni**********@hotmail.com> wrote in message
news:30**************************@posting.google.c om...
Hi,

I wondering if it is possible in asp.net to somehow execute a string
of code as if it were a page on the server. That is to say, if I
executed the following code which resided in an aspx page

<html>
<body>
<% Response.Write("Hi.") %>
</body>
</html>

the output would be

<html>
<body>
Hi
</body>
</html>

Is there some way I could execute the asp.net from above without it
being in an actual page? Can I send some server method a string and
get the output?

Thanks for any help,

Nick

Nov 18 '05 #2

P: n/a
Hey Nick,
Not directly...

What you can do though is create a file on disk, then use Server.Execute()
to 'run' that page. You can delete it when you're done.

IOW:

Take your string
dump to file with ASPX extensino
Server.Execute() to the page with an HtmlTextWriter
Return retrieve the HtmlTextWriter and the result string
Delete the page you created

Be aware though that this causes memory to be used as this new class (the
ASPX) page is created and compiled into an assembly and laoded. If you did
this a lot during processing you'd eat up memory really quickly.

What you should do instead is build a few generic pages that you can use
over and over and do some sort of processing inside those pages that might
be more dynamic.
+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/webblog/
----------------------------------
Making waves on the Web
"nick" <ni**********@hotmail.com> wrote in message
news:30**************************@posting.google.c om...
Hi,

I wondering if it is possible in asp.net to somehow execute a string
of code as if it were a page on the server. That is to say, if I
executed the following code which resided in an aspx page

<html>
<body>
<% Response.Write("Hi.") %>
</body>
</html>

the output would be

<html>
<body>
Hi
</body>
</html>

Is there some way I could execute the asp.net from above without it
being in an actual page? Can I send some server method a string and
get the output?

Thanks for any help,

Nick

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.