473,738 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2414
"acb" <ch******@gmail .com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.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 SayWelcomeState ment()
{
return "Hello World";
}
}
}

I compiled it into a release DLL.

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

using System;
using System.Collecti ons.Generic;
using System.Text;

namespace ConsoleApplicat ion1
{
class Program
{
static void Main(string[] args)
{
SimpleComponent .SimpleComponen t scMessage = new
SimpleComponent .SimpleComponen t();

Console.WriteLi ne (scMessage.SayW elcomeStatement ());
Console.ReadKey ();
}
}
}

On the other hand, the code below does not compile

using System;
using System.Collecti ons.Generic;
using System.Text;
using SimpleComponent ; // this is different

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

Console.WriteLi ne (scMessage.SayW elcomeStatement ());
Console.ReadKey ();
}
}
}

It returns the error: "'SimpleCompone nt' 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 SayWelcomeState ment()
{
return "Hello World";
}
}
}

I compiled it into a release DLL.

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

using System;
using System.Collecti ons.Generic;
using System.Text;

namespace ConsoleApplicat ion1
{
class Program
{
static void Main(string[] args)
{
SimpleComponent .SimpleComponen t scMessage = new
SimpleComponent .SimpleComponen t();

Console.WriteLi ne (scMessage.SayW elcomeStatement ());
Console.ReadKey ();
}
}
}

On the other hand, the code below does not compile

using System;
using System.Collecti ons.Generic;
using System.Text;
using SimpleComponent ; // this is different

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

Console.WriteLi ne (scMessage.SayW elcomeStatement ());
Console.ReadKey ();
}
}
}

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

Again thank you for your help.

Nov 24 '05 #5
"Garfield" <pa******@bigpo nd.net.au> wrote in message
news:eR******** ******@TK2MSFTN GP10.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.Collecti ons.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="Defau lt.aspx.cs" Inherits="_Defa ult" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed 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.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using NsNeCl;

public partial class _Default : System.Web.UI.P age
{
protected void Page_Load(objec t 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.Tex t = NEMessage1.SayH ello();

/* 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.Tex t = NEMessage2.SayH ello();
}
}
This solution works.

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

Class Library NsEqCl. Build release dll.

using System;
using System.Collecti ons.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="Defau lt.aspx.cs" Inherits="_Defa ult" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed 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.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using NsEqCl;

// Intellisence identifies two methods in NsEqCl
public partial class _Default : System.Web.UI.P age
{
protected void Page_Load(objec t 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.Tex t = NEMessage1.SayH ello();

// 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.Tex t = NEMessage2.SayH ello();

}
}

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="Defau lt.aspx.cs" Inherits="_Defa ult" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed 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.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using NsEqCl;

public partial class _Default : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
// This code does not work
//NsEqCl NEMessage1 = new NsEqCl();
//lblMessage1.Tex t = NEMessage1.SayH ello();

// This code works
NsEqCl.NsEqCl NEMessage2 = new NsEqCl.NsEqCl() ;
lblMessage2.Tex t = NEMessage2.SayH ello();

}
}

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.goo glegroups.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
2173
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 pattern for doing some task quite well. This usually leads me to a search on today's greatest technical tool, The Internet. I indefinitely uncover many potential code snippets, components, etc. and have to weed through them to find the best one...
13
9647
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 assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
3
6024
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 as Enteredstreet. If the street is found I then want to display a message box saying what table the street name is in. The code I am currently trying to use is this: Sub dbOpentableX() Dim dbsAddSampling As Database
1
8009
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 under 2002) Create a form and add two buttons (bottom right) and a panel (fill the top of the form) Anchor the buttons to the bottom right and anchor the panel to top bottom left and right. set all three controls access level to protected
3
25284
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 user control to invoke a method in the parent form. This code doesn't seem to work for me, I've tried it a number of times with very simple test cases (A user control with a single button and a parent form with a single text box) and it always...
9
6604
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 and read from Access files in C# application without having Access in this PC in this case we install MDAC , Is there any thing similar to MDAC for Excel ? if yes where can I download it ? what is the name of the file ?
4
2970
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 intent: Accept the COM or COM+ class name, function-name and input parameter (fixed string parameter) as string inputs and execute(invoke) the function at run time.
1
2978
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 the second is a custom VB6 COM component. So I was reading about AspCompat=true and it seemed like it would be a good fit for our app. From what I can tell both of the COM components that we are using are STA and we are creating the components in...
7
6508
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 Microsoft.SqlServer.Management.Smo; Unfortunately, MSSQL 2005 and MSSQL Express keep them in different place. For MSSQL2005 they are located in C:\Program Files\Microsoft SQL Server \90\SDK\Assemblies and for MSSQL Express you can find them in C:
3
1515
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: dzien=self.components.Calendar.GetDate().GetDay() for i in range(1,8): act=dzien+i -1 eval( 'self.components.d' + str(i) + '.text = "'+ str(act) + '"')
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6750
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.