Custom server controls

modularbeing

Regular
Joined
Jan 8, 2004
Messages
63
I want to create a composite server control for a new project im working on and it looks simple enough to do. However I want the control to show up in the Design environment like a regular asp control. I know I have to add extra tags to the code for this to work. Does anyone know of any code samples that does this in vb.net? all samples I have found are c# or do not have this functionality.

thanks,
Josh
 
However I want the control to show up in the Design environment like a regular asp control.
Not quite sure what you meant by that:
1. If you mean that the control will be displayed in design time as what it should look like and not a grey box, then Custom Controls should do that. Unless you created an User Control (*.ascx). If you want to add a Cusom Control, you can add a new "Web Control Library" project to your solution or create a class that inheret from System.Web.UI.Control or System.Web.UI.WebControls.WebControl.

2. Or if you mean that the control will be displayed in the Toolbox (on the left), then:
i. Right click on one of the tabs (or create a new one)
ii. Choose "Customize Toolbox"
iii. Choose ".Net Framework Component" tab
iv. Click on Browse button and locate your *.dll or *.exe control file.

If you need help building a Custom Control, try here. Hope this helps.
 
I am refering to custom control. the one test control I made worked but in the IDE I got a grey box that said error on it. All the control was was a composite of a text box and a required field validator. Another problem I was having was when I put the control in the toolbox and tried to drag n drop it onto the form it did nothing except add a reference to my project....

thanks,
Josh
 
I made another simple control and this one gets a parser error. But I cannot see what is wrong with this...

Control code:
Code:
Imports System
Imports System.web
Imports System.Web.UI
Imports System.ComponentModel
Namespace MyControl
    Public Class testControl
        Inherits System.Web.UI.WebControls.WebControl

        Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
            writer.Write("<h1>Hello World<h1>")
        End Sub

    End Class
End Namespace

Page Code:
Code:
<%@ Register TagPrefix="JB" Namespace="MyControl" Assembly="testControl"%>

<JB:testControl runat="server"/>
 
Back
Top