Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Creating components in VS.NET


Message #1 by "Nick Charlesworth" <nick@f...> on Tue, 20 Aug 2002 16:13:59
Well Greg.....
I will put up an example and explain u how to write a component in VB.NET
and use it in ASP.NET. 

Well There are 2 ways... 
1. Have the component project as well as the ASP project in the same
solution
2. Develop 2 different project within 2 diff solution corresponding

The difference between the two is while referencing the dll can be done easy
for development issue if u use the Step 1. But letmme explain to u in Step 2
so Step 1 becmes easy....

HOW TO WRITE AND USE COMPONENT DONE IN VB.NET AN USE IT IN ASP.NET

In the VB project have the NameSpace as DataAccess and let the Class Names
be Connection, DataManip

NameSpace DataAccess
	Private sub Class Connection
		Public Function SetConnStr()
			<.. Ur Code goes here ..>
		End Function
		Public function GetConnection()
			<.. Ur Code goes here ..>
		End Function
	End Class
	Private sub Class DataManip
		Public Function GetTable1()
			<.. Ur Code goes here ..>
		End Function
		Public function GetTable2()
			<.. Ur Code goes here ..>
		End Function
	End Class
End NameSpace


This will be the structure of code. Once u compile the complete code.. a ll
is created at the /bin directory of the project... say u have ur project in
"d:/" directory then the dll exists in  - - -
d:/<ProjectName>/bin/<projectname>.dll

NOTE : Copy this dll and paste it in a seperate folder day
"d:/BuilDlls/<projectname>.dll. I will explain below why u need to copy.....

Now before u start coding in the aspx pages....
reference the dll. This can be done by adding the dll to the 'Reference'
Node of the Project in the solutionExplorer. -- Right-Click on the Reference
Node and click on add. Then browse thro the folder where u copied the dll
from the VB project (remember that u go to the folder where u copied and not
into the bin directory of the VB project for the dll), select the dll and
say add... 

Now why i asked u to copy was that if in case u had referenced the dll from
the VB projects bin directory then later if u change some thing in the VB
project and compile it.... u will loose ur old copy of dll... though u may
have a copy in the aspx projects bin directory. its always better  have an
another cpy for sure.....

In the aspx page now u can call the dll by

Import DataAccess.Connection
Import DataAccess.DataManip

In case u need to call the function u can just call by
Private Sub Page_Load
	SetConnStr()
End Sub

Have a easy go and keep me posted if u have any issues ...!!!!

==============================
S.Ramanujam
Programmer Analyst
Cognizant technology Solutions (p) Ltd. - CTS
38 & 39 Whites Road,
WCB - Whites Road Circular Building
Royapettah, Chennai - 600014
Ph : +xx xx xxx xxxx Extn 5113 [Off]
     : +xx xx xxx xxxx                 [Res]


-----Original Message-----
From: greg [mailto:gregarobinson@h...]
Sent: Tuesday, August 27, 2002 7:46 PM
To: ASPX_Professional
Subject: [aspx_professional] Re: Creating components in VS.NET


> Hi all,

> I am wanting to create a Data Access component for my ASP.NET application.

I>  am using Visual Studio.NET to build the project with.

> How do I make a component and compile it to dll in VS.NET so i can use 
the 

> <%@ Import NameSpace="DataAccess" %>

> tag in my aspx files.

> I have tried adding a 'Component Class' from the new item menu but this 
j> ust adds a .vb class file.

> thanks,

> Nick




Check out the MS code blocks too.  There is one for Data Access using SQL 
Server.
---

ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442

ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450

These books are a complete reference to the ASP.NET namespaces 
for developers who are already familiar with using ASP.NET. 
There is no trivial introductory material or useless .NET 
hype and the presentation of the namespaces, in an easy-to use 
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes, 
giving you those real-world tips that the documentation doesn't 
offer, and demonstrating complex techniques with simple 
examples.  

---


  Return to Index