stuck with this simple code

Discussion in 'ASP .Net' started by Davíð Þórisson, Oct 24, 2004.

  1. I don't get it... so simple code but it's bringing an error which goes away
    if I skip that <script Src="initialize.cs"> part...
    ("CS0038: Cannot access a nonstatic member of outer type
    'System.Web.UI.Page' via nested type 'default_aspx.Initialize'")
    PS it's running .Net 2.0 which explains the "ClassName" attribute in Page
    directive


    ===default.aspx====
    <%@ Page CompileWith="default.aspx.cs" ClassName="default_aspx" %>
    <script Src="initialize.cs" runat="server"/>
    <html>
    <body>
    <asp:Literal ID="LitBody" runat="server"/>
    <asp:Literal ID="LitBody2" runat="server"/>
    </body>
    </html>

    ===initialize.cs===
    public class Initialize
    {
    void Page_Load(object sender, System.EventArgs e)
    {
    LitBody2.Text = "Texti 2";
    }
    }
     
    Davíð Þórisson, Oct 24, 2004
    #1
    1. Advertising

  2. the problem seems to be twofold

    1) cannot access the Literal on the default.aspx page
    2) if I include
    using system;
    ....etc...

    in top of my initialize.cs file a second error comes:
    CS1519: Invalid token 'using' in class, struct, or interface member
    declaration

    I can't understand why it doesn't understand "using" in a c# file???
     
    Davíð Þórisson, Oct 24, 2004
    #2
    1. Advertising

  3. ok since I'm not getting any replies I'll try to figure out myself but I
    suspect it's a scope issue so please can anyone tell me, is there some c#
    syntax to tell me where in the scope my code is running?
     
    Davíð Þórisson, Oct 25, 2004
    #3
  4. Try this:

    <%@ Page CompileWith="default.aspx.cs" ClassName="default_aspx" %>
    <script language="C#" runat="server"/>
    void Page_Load(object sender, System.EventArgs e)
    {
    LitBody2.Text = "Texti 2";
    }
    </script>
    <html>
    <body>
    <asp:Literal ID="LitBody" runat="server"/>
    <asp:Literal ID="LitBody2" runat="server"/>
    </body>
    </html>




    "Davíð Þórisson" wrote:

    > I don't get it... so simple code but it's bringing an error which goes away
    > if I skip that <script Src="initialize.cs"> part...
    > ("CS0038: Cannot access a nonstatic member of outer type
    > 'System.Web.UI.Page' via nested type 'default_aspx.Initialize'")
    > PS it's running .Net 2.0 which explains the "ClassName" attribute in Page
    > directive
    >
    >
    > ===default.aspx====
    > <%@ Page CompileWith="default.aspx.cs" ClassName="default_aspx" %>
    > <script Src="initialize.cs" runat="server"/>
    > <html>
    > <body>
    > <asp:Literal ID="LitBody" runat="server"/>
    > <asp:Literal ID="LitBody2" runat="server"/>
    > </body>
    > </html>
    >
    > ===initialize.cs===
    > public class Initialize
    > {
    > void Page_Load(object sender, System.EventArgs e)
    > {
    > LitBody2.Text = "Texti 2";
    > }
    > }
    >
    >
    >
     
    =?Utf-8?B?U0FOVE9TSA==?=, Nov 2, 2004
    #4
    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. BW
    Replies:
    0
    Views:
    303
  2. SZ
    Replies:
    11
    Views:
    587
    Richard Bos
    Nov 18, 2004
  3. saurabh9

    stuck in simple css formatting

    saurabh9, Oct 17, 2008, in forum: HTML
    Replies:
    5
    Views:
    432
  4. TheSaint
    Replies:
    9
    Views:
    622
    TheSaint
    Jun 7, 2011
  5. Chris Finch

    stuck on simple problem!

    Chris Finch, Feb 28, 2007, in forum: Ruby
    Replies:
    4
    Views:
    131
    Tim Becker
    Feb 28, 2007
Loading...

Share This Page