Code blocks are not supported in this context

Discussion in 'ASP .Net' started by John Cantley, Dec 10, 2003.

  1. John Cantley

    John Cantley Guest

    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
     
    John Cantley, Dec 10, 2003
    #1
    1. Advertising

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

    "John Cantley" <> wrote in message
    news:ew#...
    > 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
    >
    >
     
    Kevin Spencer, Dec 11, 2003
    #2
    1. Advertising

  3. John Cantley

    ant177 Guest


    > 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

    --
    ant17
    -----------------------------------------------------------------------
    ant177's Profile: http://www.highdots.com/forums/m156
    View this thread: http://www.highdots.com/forums/t63805
     
    ant177, Dec 14, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arjen
    Replies:
    3
    Views:
    449
    Scott Allen
    Feb 27, 2005
  2. Microsoft

    Controls that contain code: Code Blocks Not Supported

    Microsoft, Dec 14, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    422
    Anthony Williams
    Dec 14, 2005
  3. matt
    Replies:
    1
    Views:
    274
    George Ogata
    Aug 6, 2004
  4. Corey
    Replies:
    9
    Views:
    148
    Corey
    Jun 11, 2005
  5. Steven Taylor
    Replies:
    9
    Views:
    256
    Brian Candler
    Apr 27, 2009
Loading...

Share This Page