Custom Web Control not showing up in Toolbox

J

John Kotuby

Hi all,
This is my first time trying to creaet and use a custome Web Control in a
Web Site project in ASP.NET 2.0 with VS 2005 and VB. I created the control
in a separate Web Control Library project. The original code for that
control was written in VS 2003 for .NET 1.1.

I created a Web Project and pulled the VB module into the project. I
compared the syntax to the VB template classs that was built and it looked
very similar. I then discarded the original template and built the Control
project without an error. I have read in a Wrox book, "VS 2005 can
automatically add the control to the toolbox as long as the solution
contains the Web Control Library project.

So I opened up my Web Site project and added the existing item
WebCtrlXLS.vbproj. No luck with the control showing up. The code is small so
I am including it. Any help would be appreciated...thanks.

-----------------------------------------------------
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

<ToolboxData("<{0}:ExportPanel runat=server>" _
+ "</{0}:ExportPanel>")> _
Public Class ExportPanel
Inherits System.Web.UI.WebControls.Panel

#Region " Public Properties "
'Contains the list of supported export applications
Public Enum AppType
HTML
Word
Excel
PowerPoint
WordPerfect
End Enum

'Manage the requested export type
Private m_ExportType As AppType
<Bindable(True), Category("Behavior"), DefaultValue("Excel")> _
Public Property ExportType() As AppType
Get
Return m_ExportType
End Get
Set(ByVal Value As AppType)
m_ExportType = Value
End Set
End Property

'Filename property
Dim m_FileName As String = "File1"
<Bindable(True), Category("Appearance"), _
DefaultValue("File1")> _
Public Property FileName() As String
Get
Return m_FileName
End Get
Set(ByVal Value As String)
m_FileName = Value
End Set
End Property

'Open the application externally or host in the browser?
Private m_OpenInBrowser As Boolean = True
<Bindable(True), Category("Behavior"), DefaultValue("True")> _
Public Property OpenInBrowser() As Boolean
Get
If ExportType = AppType.WordPerfect Then

'WordPerfect can't be hosted inside IE
Return False
Else
If ExportType = AppType.HTML Then
'HTML will always be displayed
'on the current page.
Return True
Else
Return m_OpenInBrowser
End If
End If
End Get
Set(ByVal Value As Boolean)
m_OpenInBrowser = Value
End Set
End Property
#End Region

Protected Overrides Sub Render(ByVal output As _
System.Web.UI.HtmlTextWriter)
If ExportType = AppType.HTML Then
MyBase.Render(output)
Else
'get rid of all the junk that's been
'rendered to the page so far
Page.Response.Clear()
'start a very simple html document
Page.Response.Write("<html><head></head><body>")
'determine whether to open the document inside
'the browser or to an launch external app
Dim OpenType As String = "inline"
If OpenInBrowser = False Then OpenType = "attachment"
'determine the content type and file extension
Dim FileExtension As String = ".xls"
With Page.Response
Select Case ExportType
Case AppType.Excel
..ContentType = "application/ms-excel"
FileExtension = ".xls"
Case AppType.Word
..ContentType = "application/ms-word"
FileExtension = ".doc"
Case AppType.Powerpoint
..ContentType = "application/ms-powerpoint"
FileExtension = ".ppt"
Case AppType.WordPerfect
..ContentType = "application/wordperfect9"
FileExtension = ".wpd"
End Select
End With
'build full filename with extension (if necessary)
Dim FullFileName As String = FileName.Trim().ToLower
If Not FullFileName.EndsWith(FileExtension) Then
FullFileName += FileExtension
End If
'Output the HTML header
Page.Response.AddHeader("Content-Disposition", _
OpenType + ";filename=" + FullFileName)
'Output the contents of the panel
MyBase.RenderChildren(output)
'End the HTML document
Page.Response.Write("</body></html>")
Page.Response.End()
End If
End Sub
End Class
-------------------------------------------
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

Just drag the control's DLL onto your toolbox.
 
J

John Kotuby

Steve,
Another quick question. Does that mean I do not have to include the
WebCtrlXLS.vbproj project in my WebSite project or even make a reference to
the dll?

For instance... just place the DLL in the BIN folder and then drag it into
the tool box? Sorry for the rookie question. I just want to keep the web
project as light as possible.

Steve C. Orr said:
Just drag the control's DLL onto your toolbox.
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

If you drag the control's DLL onto your toolbox then you don't need to
reference the control in any other way at all. Visual Studio will take care
of everything else.

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net


John Kotuby said:
Steve,
Another quick question. Does that mean I do not have to include the
WebCtrlXLS.vbproj project in my WebSite project or even make a reference
to the dll?

For instance... just place the DLL in the BIN folder and then drag it into
the tool box? Sorry for the rookie question. I just want to keep the web
project as light as possible.
 
J

John Kotuby

Steve, in VS 2005 ..

I placed the compiled.dll in the BIN folder of my Web Site project. When I
just dragged it to the Toolbox from the Solution Explorer it created a
strange reference in the toolbox...

file:///C:\develpopment....<path to dll>

I got around that by right-clicking in the toolbox and selected "Add a Tab".
Then from that tab area, "Choose Items" which displayed a list of available
tools... many in the Global Cache or in C:\program files\microsoft visual
studio 8\smartdevices\SDK\...
I navigated to the BIN location in my development area, found the DLL and
after it appeared in the listing, marked the checkbox...voila it is there
and now works fine.

Even the instructions in the Toolbox say to drag an item there... don't know
why I got the strange results.

Anyway, now the ExportPanel is in the toolbox and works fine. I just need to
find out how to generate multiple Worksheets in the same WorkBook. The only
answers I see out there are using the Microsoft Office XML toolkit (very
involved) or a 3rd part tool (expensive).

Thanks for your help. The ExportPanel will make my work easier and gave me a
good introduction to creating custom Web Server controls.

OOPS! I just tried dragging the DLL from Windows Explorer onto the toolbox
and it worked! Imagine that... a simple few words missing in the
communication and look what happens. LOL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,795
Latest member
YolandaCar

Latest Threads

Top