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
-------------------------------------------
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
-------------------------------------------