Getting Started Question

  • Thread starter Thread starter Cyril Kearney
  • Start date Start date
C

Cyril Kearney

I am trying to learn C# over the internet. My ISP only allows .aspx
files. All .cs files are rejected.

The tutorials on the Internet are aimed at people able to run .cs
files from the command line. I can't do this.

Here's an almost universal first example.

using System;
class HelloWorld
{
public static void Main()
{
Console.WriteLine("Hello World !");
}
}

I've modified it to this and saved it as test.aspx but it doesn't run

<%@ Page language="c#" Debug="true"%>

<script Language="c#" runat="server">
using System;
class HelloWorld
{
public static void Main()
{
Response.Write("Hello World !");
}
}
</script>

I can't figure out what I'm doing wrong. Shouldn't all C# programs be
able to run in an .aspx file using Response.Write instead of
Console.WriteLine?

Thanks in advance for any help.
 
Cyril Kearney said:
I am trying to learn C# over the internet. My ISP only allows .aspx
files. All .cs files are rejected.

The tutorials on the Internet are aimed at people able to run .cs
files from the command line. I can't do this.

Any reason you can't install the .NET framework on your own computer
and compile and run your own programs?
Here's an almost universal first example.

using System;
class HelloWorld
{
public static void Main()
{
Console.WriteLine("Hello World !");
}
}

I've modified it to this and saved it as test.aspx but it doesn't run

<snip>

No, it wouldn't.
I can't figure out what I'm doing wrong. Shouldn't all C# programs be
able to run in an .aspx file using Response.Write instead of
Console.WriteLine?

No. ASP.NET works on pages, not programs - the above is a program, with
a program entry point (Main).

I suggest you try to find an ASP.NET tutorial instead of a plain .NET
tutorial. However, without being able to include code-behind pages,
you're going to get frustrated pretty quickly, I suspect.
 
It does not run, because you put a class, into a server side script and
expect the Main function to run. Do not confuse a console application
(which is a standalone application), with an asp.net page (which is just a
page executed by the aspnet process - which is an application).

That being said, what you can put in a server side script block like that
are functions. These function can be event handler for events - in which
case they will run when the event occurrs. Or they can be regular functions,
which will be run when you call them (from an event, or an inline script
block).

You can also use <% %> server side script blocks, which can contain lines
of code. So something like:

<%
Response.Write("Hello");
%>

I recommend you get familiar with the asp.net model to learn about how the
code behind model works, and how the model for putting all your code
directly into the .aspx works.
 

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

Back
Top