Code blocks are not supported in this context

J

John Cantley

What does this mean, have been doing services and windows apps for awhile
now, don't remember doing anything special to get them to work

tried
<script runat="server"> or whatever it was
string sContent;
sContent = GetContent("Default");
Response.Write(sContent)
</script>

<%
string sContent;
sContent = GetContent("Default");
Response.Write(sContent)
%>

GetContent is a declared this way public string GetContent(string pPage)

Am I doing something wrong or not have something set?

John
 
K

Kevin Spencer

The ASP.Net Page class is a class. You can't just put a block of code
anywhere you want to in a class. It has to go inside a function, such as the
Page_Load Event Handler.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
A

ant177

The ASP.Net Page class is a class. You can't just put a block of code
anywhere you want to in a class. It has to go inside a function, suc
as the
Page_Load Event Handler.

Hmmm, I guess when you put it like that it explains a few things bu
makes life a whole lot more difficult, or at least a change in attac
method!

I come from an ASP/PHP coding background and am used to be able to jus
inject server generated stuff anywhere I like. I'm going to try and ta
along with this thread because I'm experiencing the exact same issue a
the minute.
I have written a user control which basically just creates a nic
themed box in the style of my site, the content for the control i
placed within the tags, everything works fine until I add <% %
anywhere like so:


Code
-------------------
<Box:ShadedBox Width="90%" BoxTitle="Registration" runat="server">

<%="hi" %>

</Box:ShadedBox
-------------------


And the page falls over with the error "Code blocks are not supporte
in this context". Is there any way of injecting server side code int
this section WITHOUT resorting to using the page_load method? I want t
be able to keep some of my code in the aspx file rather than the aspx.c
code-behind file.
Regards,
Anthony William
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top