Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2003, 05:31 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 137
Thanks: 0
Thanked 0 Times in 0 Posts
Default C# code not working with ASP.NET

I have just purchased Beginning ASP.NET 1.0 with C# by Wrox Press. And have fallen at the first hurdle, which is I can't get the test program to work. I have made sure it's saved as .aspx file yet all it does is display the HTML and on viewing the page source in the browser I can still see the script itself.

The code I was required to type word for word was as follows:


<script language="c#" runat="server">

void Page_Load()
{
time.text=DateTime.Now.Hour.ToString() + ":" +
        DateTime.Now.Minute.ToString() + ":" +
        DateTime.Now.Second.ToString();
}


<html>
<head><title>The Punctual Web Server</title></head>
<body>
<h1>Welcome</h1>
In WebServerLand the time is currently:
<asp:label id="time" runat="server" />
</body>
</html>

Being new to ASP.NET this code seems wrong as shouldn't any ASP code still be embedded using <% and %> and shouldn't all ASP.NET pages have the following header:

<%@Page Language"C#" runat="server">

I have .NET frame work and am running the scripts on my own machine but it just does work ! I have tried a script using VB.NET and classic ASP and that works fine. Any ideas ? is the code presented in book correct? am I doing something wrong?

I am using MS Windows XP Professional and have IIS 5.1 installed and have tested scripts on my machine using a localhost


Gaz
__________________
Gaz
 
Old August 23rd, 2003, 10:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Dear new friend:
First welcome to ASP.NET & I wish u good lock!
Then u have some mistakes as:
1- Didnt closed <script> tag -> </script>
2- Text Attribute of Label first "T" is Capital.

feel free to ask ur question in forum;)


Always:),
Hovik Melkomian.
 
Old August 24th, 2003, 04:23 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 137
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Firstly the missing script tag was an error on my part. That should of been there already, that was just a paste error on my part.

I have made the adjustments as recommended but it still doesn't work. On running the code all it does is display the HTML code and no time!

On running the code if I view source in the browser all the source(including the ASP.net/c#) is available to see in the browser!

Maybe I have overlooked something in the setup of LOCALHOST etc on my PC? As mentioned earlier a ASP.NET script with VB.NET works fine!

<script language="C#" runat="server">

void Page_Load()
{
  time.Text=DateTime.Now.Hour.ToString() + ":" +
        DateTime.Now.Minute.ToString() + ":" +
        DateTime.Now.Second.ToString();
}
</script>

<html>
<head><title>The Punctual Web Server</title></head>
<body>
<h1>Welcome</h1>
In WebServerLand the time is currently:
<asp:label id="time" runat="server" />
</body>
</html>

I have even download the source code for each chapter of the book and attempted to run that version and it's the same as mine and doesnt work either!!! any ideas peeps!! I am so close to go back to classic ASP :-(


Gaz
 
Old August 24th, 2003, 04:52 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Gaz,

The way you have your page now, it should run fine. So the error must be caused by your setup.

In what order did you install IIS and the .NET Framework? IIS should be installed first, so the .NET Framework can set up IIS to handle .aspx pages correctly.

Take a look at this page to see how you can fix it (use regiis.exe).

The way the code is embedded in the page with <script> tags is the way it's supposed to be. You'll see <% and %> mainly used for the Page Directive and for databinding expressions.

The page could indeed have a Page Directive like this:

<%@ Page language="C#" %>

However, it is not required. The Page Directive is used to set all kinds of options that apply to the whole page like Src, CodeBehind etc. Take a look at this MSDN page for more info.

HtH,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old August 25th, 2003, 04:08 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 137
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Silly silly me. I think I know what I have done wrong! A few months back I obtained a trial verison of VISUAL STUDIO .NET from work. I basically installed the .NET framework as part of that setup and IIS was already installed. However, I recall that I uninstalled IIS for some reason and installed it back on my PC with .NET framework on it.

So I have decide to start a fresh and have have uninstalled the lot and am going to do the installation in the order both you and the Microsoft web site suggest !!!

Wish me luck!!

Gaz
 
Old August 25th, 2003, 04:15 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Good luck!! ;)


Quote:
quote:Wish me luck!!
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old August 25th, 2003, 09:54 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 137
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It works !! and what is the lesson learned: well it's never guess or skip a chapter and always follow setup instructions to the T



Gaz





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.Net 2.0 tutorial not working out so well. dclark ASP.NET 2.0 Basics 1 July 16th, 2006 07:11 PM
working with CMS from ASP.NET naidukap ASP.NET 1.0 and 1.1 Professional 0 April 2nd, 2006 05:38 AM
ASP.Net Datagrid:-My Code is not working sibajibasak General .NET 2 January 22nd, 2005 01:50 AM
ASP.Net not working astronaut_10 ASP.NET 1.0 and 1.1 Basics 1 August 27th, 2004 02:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.