Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Type or namespace not found?!

$
0
0

Hello,

"The type or namespace "Product" cou'd not be found (are you missing ''''')"

I am getting this error from my .aspx file. This is source code from a book "Beginning asp.net 4.5 in C#" chapter 3 avaliable here (scroll down) ww/w.apress.com/9781430242512

I think it is not accessing the product class in my .cs file in app_code folder. Very confusing.

-----------------------

.aspx code

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

<!DOCTYPE html>

<script runat="server">
    private void Page_Load(object sender, EventArgs e)
    {
        Product saleProduct = newProduct("Kitchen Garbage", 49.99M, "garbage.jpg"); //ERROR HERE<----
        Response.Write(saleProduct.GetHtml());
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Product Test</title>
</head>
<body></body>
</html>

---------------------

.cs code

using System;

// Define the delegate that represents the event.
public delegate void PriceChangedEventHandler();

public class Product
{    
    public string Name {get; set;}
    
    // Define the event.
    public event PriceChangedEventHandler PriceChanged;

    private decimal price;
    public decimal Price
    {
        get
        {
            return price;
        }
        set
        {
            price = value;

            // Fire the event, provided there is at least one listener.
            if (PriceChanged != null)
            {
                PriceChanged();
            }
        }
    }

    public string ImageUrl {get; set;}
    
    public string GetHtml()
    {
        string htmlString;
        htmlString = "<h1>" + Name + "</h1><br>";
        htmlString += "<h3>Costs: " + Price.ToString() + "</h3><br>";
        htmlString += "<img src='" + ImageUrl + "' />";
        return htmlString;
    }

    public Product(string name, decimal price)
    {
        Name = name;
        Price = price;
    }

    public Product(string name, decimal price, string imageUrl)
    {
        Name = name;
        Price = price;
        ImageUrl = imageUrl;
    }
}

Thank you in advance,

Tim



Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>