473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Using Components in ASP.NET (C#)

acb
Hi,

I wrote a DLL Component (using Visual Studio 2005) and managed to
include it into a C# Console application.

I am now trying to include this component into a Web project. I copy
the DLL into the bin directory but am not able to progress. Can anyone
please guide me to an online tutorial on the subject.

Thanks,
ACB

Nov 24 '05 #1
8 2381
"acb" <ch******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
am not able to progress.


What does that actually mean?
Nov 24 '05 #2
acb wrote:
Hi, hi there,

I think you also need to add it to your project's references. You can
find the "references" in your solution panel at the top right hand side.
Right click the item and select add reference, then locate your dll file
and click ok.

Hope that helps

I wrote a DLL Component (using Visual Studio 2005) and managed to
include it into a C# Console application.

I am now trying to include this component into a Web project. I copy
the DLL into the bin directory but am not able to progress. Can anyone
please guide me to an online tutorial on the subject.

Thanks,
ACB

Nov 24 '05 #3
acb
Mark and Henry,

Sorry for not explaining myself properly. Thanks to you I have had a
better look at the code and the problem was not web vs console, it was
how to properly tell the compiler that it should use the newly created
namespace. I now have functional code but I haven't yet figured one
variation. This is my situation

I have the following Class Library:

using System;

namespace SimpleComponent
{
public class SimpleComponent
{
public string SayWelcomeStatement()
{
return "Hello World";
}
}
}

I compiled it into a release DLL.

I then created a console application solution called
TextSimpleComponent. I included a reference to the DLL created above
and in Program.cs included the following. It works.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SimpleComponent.SimpleComponent scMessage = new
SimpleComponent.SimpleComponent();

Console.WriteLine (scMessage.SayWelcomeStatement());
Console.ReadKey();
}
}
}

On the other hand, the code below does not compile

using System;
using System.Collections.Generic;
using System.Text;
using SimpleComponent; // this is different

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SimpleComponent scMessage = new SimpleComponent(); // This
is different

Console.WriteLine (scMessage.SayWelcomeStatement());
Console.ReadKey();
}
}
}

It returns the error: "'SimpleComponent' is a 'namespace' but is used
like a 'type'

Again thank you for your help.

Nov 24 '05 #4
Yo acb,

I am not exactly sure, but why not try a different name for your class
name other than the same name of your namespace? That should at least
clarify where the error is comming from, the namespace or the class :)

Hope that helps
acb wrote:
Mark and Henry,

Sorry for not explaining myself properly. Thanks to you I have had a
better look at the code and the problem was not web vs console, it was
how to properly tell the compiler that it should use the newly created
namespace. I now have functional code but I haven't yet figured one
variation. This is my situation

I have the following Class Library:

using System;

namespace SimpleComponent
{
public class SimpleComponent
{
public string SayWelcomeStatement()
{
return "Hello World";
}
}
}

I compiled it into a release DLL.

I then created a console application solution called
TextSimpleComponent. I included a reference to the DLL created above
and in Program.cs included the following. It works.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SimpleComponent.SimpleComponent scMessage = new
SimpleComponent.SimpleComponent();

Console.WriteLine (scMessage.SayWelcomeStatement());
Console.ReadKey();
}
}
}

On the other hand, the code below does not compile

using System;
using System.Collections.Generic;
using System.Text;
using SimpleComponent; // this is different

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SimpleComponent scMessage = new SimpleComponent(); // This
is different

Console.WriteLine (scMessage.SayWelcomeStatement());
Console.ReadKey();
}
}
}

It returns the error: "'SimpleComponent' is a 'namespace' but is used
like a 'type'

Again thank you for your help.

Nov 24 '05 #5
"Garfield" <pa******@bigpond.net.au> wrote in message
news:eR**************@TK2MSFTNGP10.phx.gbl...
I am not exactly sure, but why not try a different name for your class
name other than the same name of your namespace? That should at least
clarify where the error is comming from, the namespace or the class :)


That's just common sense, surely...? I can't imagine naming a class the same
as the namespace containing it.
Nov 24 '05 #6
acb
"Mark Rae" <m...@mark-N-O-S-P-A-M-rae.co.uk> wrote
That's just common sense, surely...? I can't imagine naming a class the same
as the namespace containing it.


I'm too new on the subject to comment on that :-) My only observation
is that the book ASP.NET by Danny Ryan and Tommy Ryan (Hungry Minds
publishers) has examples written in a form in which the namespace and
the class have the same names.

If this is such a no-no I would suggest that an enhancement would be
say a warning by the compiler to that effect. I was impressed by the
fact that the compiler tells me that a variable I am using might not
have been properly initialised so I don't think that this should be
difficult to implement.

For the benefit of others who might encounter a problem similar to
mine, the problem ***was*** the fact the namespace and the class had
the same name.

The following code should help demonstrate the problem and reproduce
it:

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

Class Library NsNeCl. Build release dll.

using System;
using System.Collections.Generic;
using System.Text;

/* In this example, the namespace has a different name to the class. In
my tests
* this combination works.
*
* ACB - Nov 2005
*/

namespace NsNeCl
{
public class Class1
{
public string SayHello()
{
return "Hello, World";
}
}
}

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

Website CallNsNeCl. Include in this project the release dll produced in
NsNeCl.

Default.aspx code

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

<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblMessage1"
runat="server"></asp:Label>&nbsp;<br />
<asp:Label ID="lblMessage2" runat="server"></asp:Label></div>
</form>
</body>
</html>

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

File Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NsNeCl;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
/* Since the namespace in included in the class one can
automatically
* create new objects by referencing classes defined within it
*/

Class1 NEMessage1 = new Class1();
lblMessage1.Text = NEMessage1.SayHello();

/* The extended version of the code shown above. Here the
object is
* referenced using both namespace and class
*/
NsNeCl.Class1 NEMessage2 = new NsNeCl.Class1();
lblMessage2.Text = NEMessage2.SayHello();
}
}
This solution works.

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

Class Library NsEqCl. Build release dll.

using System;
using System.Collections.Generic;
using System.Text;
/* In this example, the namespace carries the same name as the class.
In my tests
* it did not work
*
* ACB - Nov 2005
*/

namespace NsEqCl
{
public class NsEqCl
{
public string SayHello()
{
return "Hello, World";
}

}
}

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

Website CallNsEqCl. Include in this project the release dll produced in
NsEqCl.

Default.aspx code

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

<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblMessage1"
runat="server"></asp:Label>&nbsp;<br />
<asp:Label ID="lblMessage2" runat="server"></asp:Label></div>
</form>
</body>
</html>

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

File Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NsEqCl;

// Intellisence identifies two methods in NsEqCl
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Error 1 The type or namespace name 'Class1' could not be
found (are you missing a using directive or an assembly reference?)
//Class1 NEMessage1 = new Class1();
//lblMessage1.Text = NEMessage1.SayHello();

// Error 1 The type or namespace name 'Class1' does not exist
in the namespace 'NsEqCl' (are you missing an assembly reference?)
//NsEqCl.Class1 NEMessage2 = new NsEqCl.Class1();
//lblMessage2.Text = NEMessage2.SayHello();

}
}

Nov 25 '05 #7
acb
Hi,

While assembling my previous I made a muck up in the source behind
Website CallNsEqCl. I am reposting the source in its entirety below. I
would like to point out that the line "using NsEqCl;" may be removed
when using the Namespace.Class referencing.

Include in this project the release dll produced in NsEqCl.

Default.aspx code

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

<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblMessage1"
runat="server"></asp:Label>&nbsp;<br />
<asp:Label ID="lblMessage2" runat="server"></asp:Label></div>
</form>
</body>
</html>
File Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NsEqCl;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// This code does not work
//NsEqCl NEMessage1 = new NsEqCl();
//lblMessage1.Text = NEMessage1.SayHello();

// This code works
NsEqCl.NsEqCl NEMessage2 = new NsEqCl.NsEqCl();
lblMessage2.Text = NEMessage2.SayHello();

}
}

So unlike what I observed originally, when namespace = class name it
seems that one has to use the namespace.class notation.

Regards
ACB

Nov 25 '05 #8
"acb" <ch******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I'm too new on the subject to comment on that :-) My only observation
is that the book ASP.NET by Danny Ryan and Tommy Ryan (Hungry Minds
publishers) has examples written in a form in which the namespace and
the class have the same names.
http://www.amazon.com/gp/product/076...books&v=glance

Take a look at some of the reviews, specifically those which comment on the
errors in the code examples.
For the benefit of others who might encounter a problem similar to
mine, the problem ***was*** the fact the namespace and the class had
the same name.


So now you know for yourself that the book you were using leaves a lot to be
desired... :-)
Nov 25 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mario T. Lanza | last post by:
Greetings, I don't know about you guys but on many occasions I've asked myself whether or not someone else has solved a particular programming issue -- whether or not they developed a clever...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
3
by: Katrina | last post by:
I am trying to write a piece of code that will search through a number of different tables (current one being tableNm) to look for a specific street name that has been entered by the user and saved...
1
by: Jason Hickey | last post by:
Has there been a change in the way the UI designer handles winform inheritance in the 2003 version of visual studio. Consider the following (try it if you are using 2003 Everything seems to work...
3
by: Todd Schinell | last post by:
Back in July, Jeffery Tan posted this: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OWOTdf0VDHA.2296%40cpmsftngxa06.phx.gbl In response as to how to get click events from a...
9
by: [Yosi] | last post by:
Can I make an Excel file without having Excel in my PC ? I want to create Excel files from my C# application , then open those files later in another PC who have Excel installed . As we can open...
4
by: Praveen Chandra | last post by:
Hi, I just wanted to put down the issue with more detailed information so that you can help us get to the right Microsoft resource for a solution! Here is the problem description... Our...
1
by: Nicholas Palmer | last post by:
Hi all, Got a question about the AspCompat=true page property. First a little background. We have an ASP.NET app that uses two COM components. The first is the Microsoft OWC 11 components and...
7
by: Olegus | last post by:
Hello, in order to perform backup/restore MSSQL database using SMO, one needs to reference several namespaces in a backup class : using Microsoft.SqlServer.Management.Common; using...
3
by: Michal Lipinski | last post by:
Hi its my first post. I have a problem, I want to user eval() function in a for loop to set labels to staticText so i done something like this: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.