Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to see both classes in a .cs file

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I am having an issue with VS 2008 recognizing my class. The file has 2 classes in it (same namespace and sees one but not the other.

Here is my Class page
**************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SimpleEvent
{
public class Product
{
private string name;
public string Name
{
get
{
return this.name;
}
set
{
Object old = this.name;
this.name = value;
OnPropertyChange(this, new PropertyChangeEventArgs("Name", old, value));
}
}

// Delegate
public delegate void PropertyChangeHandler(object sender, PropertyChangeEventArgs data);
// The event
public event PropertyChangeHandler PropertyChange;
// The method which fires the Event
protected void OnPropertyChange(object sender, PropertyChangeEventArgs data)
{
// Check if there are any Subscribers
if (PropertyChange != null)
{
// Call the Event
PropertyChange(this, data);
}
}
}

public class PropertyChangeEventArgs : EventArgs
{
public string PropertyName { get; internal set; }
public object OldValue { get; internal set; }
public object NewValue { get; internal set; }
public PropertyChangeEventArgs(string propertyName, object oldValue, object newValue)
{
this.PropertyName = propertyName;
this.OldValue = oldValue;
this.NewValue = newValue;
}
}
}
**************************************

Here is my .aspx page:

*************************************************
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SimpleEvent._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns=" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
this is a test
</div>
</form>
</body>
</html>
*************************************************

My codebehind page looks like:

**************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SimpleEvent
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
this.Product = new Product();
this.Product.OnPropertyChange += new Product.PropertyChangeHandler(PropertyHasChanged);
}
protected void Page_Load (object sender, EventArgs e)
{
this.Product.Name = "New name";
}

public void PropertyHasChanged (object sender, PropertyChangeEventArgs data)
{
if(data.PropertyName == "Name")
{
this.ProductLabel.Text = (string)data.NewValue + " was " + (string)data.OldValue;
}
}
}
}
**************************************

It sees the PropertyChangeEventArgs class fine, but says it can't see the Product class:

'SimpleEvent._Default' does not contain a definition for 'Product' and no extension method 'Product' accepting a first argument of type 'SimpleEvent._Default' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\tfs\My Documents\Visual Studio 2008\Projects\SimpleEvent\SimpleEvent\Default.aspx.cs

How come it can see one class and not the other?

Thanks,

Tom
 
Nevermind.

I found my problem.

This was a sample program I was using and it was seeing the class, but there was no local variable (Product) defined. When I added that, it worked fine.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top