Introducing Custom Controls
page 4 of 6
by . .
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 27417/ 57

Coding, Compiling & Rendering

Adding Code

Usually code will be added in the Render event -

Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)

...code...

End
Sub

Note here that we Override the Render event. You can also add the code in any one of the other events.

I will be looking at this in more detail later on.

Compiling

Compiling the custom control is as simple as running the following at the command prompt (or building it in VS.NET) -

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

Displaying

As with a class library, you simply put the resulting DLL into the /bin directory of the target application and then register the tag on each page you want to use it on -

<%@ Register TagPrefix="MyPrefix" Namespace="AGASP" Assembly="AGASP" %>

To register the control on the page. Then use the normal server/user control style to include it.

<MyPrefix:ctrl1 id="TestControl" runat="server" />

Note that the syntax is - TagPrefix:ClassName. This allows you to have multiple controls in one namespace (again making a reference to the Web Server Controls).


View Entire Article

User Comments

Title: Custom vs. User control BLUNDER – user control CAN be referenced in the code.   
Name: Igor Kikena
Date: 2005-03-14 3:53:38 PM
Comment:
Implementing page can reference user control exactly the same way as custom control, otherwise there is really little use for them. And Yes, it does not create user control variable when you drag and drop it on the page, contrary to custom control. So leave your mouse alone and strike the damn keyboard and enjoy user controls in the code behind.

Igor Kikena
Title: Ok..Its a good Topic   
Name: Esha
Date: 2005-03-08 4:47:14 AM
Comment:
I will be better if u give an sample code for building custom control and embedding it in asp webform page
Title: airo   
Name: airo
Date: 2005-01-13 10:13:47 PM
Comment:
Excellent topic and well explained.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 12:22:46 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search