stuck with this simple code

D

Davíð Þórisson

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";
}
}
 
D

Davíð Þórisson

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???
 
D

Davíð Þórisson

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?
 
G

Guest

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>
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top