Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 May 14th, 2008, 09:09 PM
Authorized User
 
Join Date: Apr 2008
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 5 First Try It Out

Hello,

When I entered the first Try It Out in Chapter 5 I got the following error and warning. I am not sure how to correct it

error and warning messages

Warning 1 C:\BegASPNET\Site\PlanetWrox\Demos\CalculatorDemo. aspx: ASP.NET runtime error: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. (C:\BegASPNET\site\planetwrox\web.config line 52) C:\BegASPNET\Site\PlanetWrox\Demos\CalculatorDemo. aspx 1 1 C:\BegASPNETError 2 It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. C:\BegASPNET\Site\PlanetWrox\web.config 52

Line 52 of the web.config file contains the following section

<pages>
            <controls>
                <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
     </controls>
  </pages>

Markup code

<% @Page Language="C#" AutoEventWireup="true" CodeFile="CalculatorDemo.aspx.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <table class="style1">
            <tr>
                <td colspan="3">
                    <asp:Label ID="lblResult" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox ID="txtValue1" runat="server"></asp:TextBox>
                </td>
                <td>
                    <asp:DropDownList ID="lstOperator" runat="server" AutoPostBack="True">
                        <asp:ListItem>+</asp:ListItem>
                        <asp:ListItem>-</asp:ListItem>
                        <asp:ListItem>*</asp:ListItem>
                        <asp:ListItem>/</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:TextBox ID="txtValue2" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    <asp:Button ID="btnCalculate" runat="server" Font-Bold="True"
                        onclick="btnCalculate_Click" Text="Calculate" />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>

    </div>
    </form>
</body>
</html>

C# Code File

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Site_PlanetWrox_Demos_CalculatorDemo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnCalculate_Click(object sender, EventArgs e)
    {
        if (txtValue1.Text.Length > 0 && txtValue2.Text.Length > 0)
        {
            double result = 0;
            double value1 = Convert.ToDouble(txtValue1.Text);
            double value2 = Convert.ToDouble(txtValue2.Text);

            switch (lstOperator.SelectedValue)
            {
                case "+":
                    result = value1 + value2;
                    break;
                case "-":
                    result = value1 - value2;
                    break;
                case "*":
                    result = value1 * value2;
                    break;
                case "/":
                    result = value1 / value2;
                    break;

            }
            lblResult.Text = result.ToString();
        }
        else
        {
            lblResult.Text = string.Empty;
        }
    }
}


Thank you for your help.

Brian

 
Old May 15th, 2008, 04:10 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 there,

You opened the wrong folder as a website in VWD. Normally, you should have the site in C:\BegASPNET\Site\ This in turn means you have a Demos folder here: C:\BegASPNET\Site\Demos

If you have set it up like this, then open the site as follows:

1. Choose File | Open Web Site

2. Browse to C:\BegASPNET\Site

3. The Solution Explorer should now show a Sub folder called Demos.

When you browse to the demos folder, you should see something like:

http://localhost:12345/Demos/Calculator.aspx

When you store the files at a different location (e.g. C:\BegASPNET\Site\PlanetWrox) be sure to change the path in step 2. That is, don't browse to C:\BegASPNET\Site and the end up with a PlanetWrox main folder in the Solution Explorer in VWD.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old May 15th, 2008, 09:12 PM
Authorized User
 
Join Date: Apr 2008
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

Thank you for your help. I changed my directory structure to follow the text site which corrected the error snd the example compiled and works correctly. I am finding your book very enjoyable to work through and a great teaching tool.

thanks again.

Brian

 
Old May 16th, 2008, 01:48 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 Brian,

Glad you got it working....

Have fun!

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
chapter 7 - chapter 11 pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 3 January 6th, 2008 11:40 AM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM





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