Iver's web place

Life is a journey ... taken one shot at a time!

How to create custom controls in ASP.NET part 3 of 3

Deploying Custom Controls


If you're using the Visual Studio IDE, maybe you don't know the building way from the command line. I have two files (FoxyGridView.cs and FoxyGridView.Methods.cs) and I need to generate the build from the command line. So the sintax is the next:

C:\Program Files\Microsoft Visual Studio 9.0\VC> csc /t:library /out:FoxyGridView.dll /r:System.dll /r:System.Data /r:System.Drawing /r:System.Web FoxyGridView.cs FoxyGridView.Methods.cs
Also we can set the control assembly properties, a strong assembly name consists of four parts: assembly name, version, culture, and public token key. Only we need to create a file named AssemblyInfo.css (or maybe other name), with the following code to the file:

 
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
 
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyKeyFile("KeyFile.snk")]
 


By default the Visual Studio 2008 add a file with the common attributes and the respectives comments about. Wheter you wish to sing the assembly. You can use the following command:
C:\Program Files\Microsoft Visual Studio 9.0\VC> sn -k KeyFile.snk

Don't forget to put the code and AssemblyInfo.cs file and key file into the same folder and use the following command to compile and sign the FoxyGridView.cs file to strongly named assembly, which will be named FoxyGridView.dll in this case:

C:\Program Files\Microsoft Visual Studio 9.0\VC> csc /t:library /out:FoxyGridView.dll /r:System.dll /r:System.Data /r:System.Drawing /r:System.Web FoxyGridView.cs FoxyGridView.Methods.cs AssemblyInfo.cs
To install a control to the GAC, you need to run the .NET command prompt (Start -> Programs -> Microsoft VS.NET -> VS.NET Tools -> VS.NET prompt) and start the gacutil.exe tool with -i parameter (install) and the full path to the control's dll.

gacutil.exe -i c:\Projects\FoxyGridView.dll

Adding Custom Control to the Visual Studio Toolbox


For adding your custom control to the toolbox Right-click the Toolbox area and select "Choose Items" from the pop-up menu to launch the "Choose Tool Items" dialog box.

toolbar image

After that use the "Browse" button to navigate to the directory where the assembly is located and select it.


browse image

And now, we can use the custom control from our Visual Studio Toolbox.






Resources

Professional ASP.NET 2.0 Server Control and Component Development
Dr. Shahram Khosravi
ISBN-13: 978-0-471-79350-2
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471793507.html



http://support.microsoft.com/kb/315682
Trackback URI: http://www.iver.com.mx/index.php/trackback/138

# Re: How to create custom controls in ASP.NET part 3 of 3

toolbar image, <hadiqul49@gmail.com> / 3 October, 7:55am  
avatar

Thank you for your sharing useful article. This ideas is very useful for me. I am currently doing researches on various topics. you are engaged in a development of multi-function application, you will find yourself in need of a variety of toolbar icons.

Leave a Comment



Write the captcha code you are seeing.

Comment XML feeds: RSS | Atom