Custom Control
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcontrolsvb' list.


Srini
Hi,
I have created a .vb file which contains the following text. How do i create my Custom Control.

Imports System
Imports System.Web
Imports System.Web.UI

Namespace MyCustomControls
Public Class CustomControl1 : Inherits Control
Protected Overrides Sub Render(Output as HtmlTextWriter)
Output.Write("This is my Custom Control ! The Time is now " & DateTime.Now.ToString)
End Sub
End Class
End Namespace

Regards
Srini
Reply to this message...
 
    
Alex Lowe
Srini,

Two things:

1) Compile your control into a assembly (more on assemblies and other
things at
(http://www.aspalliance.com/remas/ASP.NET/VFAQNET/ImportVsAssembly/).
Compiling a control in Visual Studio .NET is as simple as hitting
Build->Build 'Class Name' on the toolbar. If are not using Visual Studio
.NET then you will need to use the command line comiler for VB.NET
(vbc.exe is the filename of the VB.NET compiler). To compile your
control we would use a command line like this....

vbc /t:library /r:System.dll,System.Web.dll YourFileName.vb

The first switch (/t:library) tells the compiler that we want the output
of our compiled .vb file be of the library type. There are other types
so if you are curious then go to the command line and type vbc and hit
enter. The second switch (/r:System.dll,System.Web.dll) references the
necessary assemblies so we have access to the necessary classes.

Now, to use your control in an ASP.NET page, you will need to use the
Register directive. It would look something like this....

<%@ Register TagPrefix="myControls" Namespace="myControls"
Assembly="YourFileName" %>

and in the page you could use something like....

<myControls:YourFileName id="CustomControl1" runat="Server" />

hth,

Alex - AspFriends.com Moderation Team
Microsoft MVP - ASP.NET

***********************************************************
Have a question about using client side coding in your ASP.NET pages?
Send your question to [aspngclient]
(http://www.aspfriends.com/aspfriends/aspngclient.asp)
***********************************************************

-----Original Message-----
From: Srini [mailto:Click here to reveal e-mail address]
Sent: Monday, January 28, 2002 10:48 AM
To: aspngcontrolsvb
Subject: [aspngcontrolsvb] Custom Control

Hi,
I have created a .vb file which contains the following text. How do i
create my Custom Control.

Imports System
Imports System.Web
Imports System.Web.UI

Namespace MyCustomControls
Public Class CustomControl1 : Inherits Control
Protected Overrides Sub Render(Output as HtmlTextWriter)
Output.Write("This is my Custom Control ! The Time is now " &
DateTime.Now.ToString)
End Sub
End Class
End Namespace

Regards
Srini
| [aspngcontrolsvb] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcontrolsvb.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
 
System.DateTime
System.Web.UI.HtmlTextWriter




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com