Custom Web Control not showing up in Toolbox

Discussion in 'ASP .Net' started by John Kotuby, May 9, 2007.

  1. John Kotuby

    John Kotuby Guest

    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
    -------------------------------------------
     
    John Kotuby, May 9, 2007
    #1
    1. Advertising

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

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


    "John Kotuby" <> wrote in message
    news:%...
    > 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
    > -------------------------------------------
    >
    >
     
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider], May 9, 2007
    #2
    1. Advertising

  3. John Kotuby

    John Kotuby Guest

    Thanks Steve,

    I guess you recognize your code and thanks for providing it!


    "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]" <> wrote in
    message news:...
    > Just drag the control's DLL onto your toolbox.
    >
    > --
    > I hope this helps,
    > Steve C. Orr,
    > MCSD, MVP, CSM, ASPInsider
    > http://SteveOrr.net
    >
    >
    > "John Kotuby" <> wrote in message
    > news:%...
    >> 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
    >> -------------------------------------------
    >>
    >>

    >
    >
     
    John Kotuby, May 10, 2007
    #3
  4. John Kotuby

    John Kotuby Guest

    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 [MCSD, MVP, CSM, ASP Insider]" <> wrote in
    message news:...
    > Just drag the control's DLL onto your toolbox.
    >
    > --
    > I hope this helps,
    > Steve C. Orr,
    > MCSD, MVP, CSM, ASPInsider
    > http://SteveOrr.net
    >
    >
    > "John Kotuby" <> wrote in message
    > news:%...
    >> 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
    >> -------------------------------------------
    >>
    >>

    >
    >
     
    John Kotuby, May 10, 2007
    #4
  5. 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" <> wrote in message
    news:%...
    > 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 [MCSD, MVP, CSM, ASP Insider]" <> wrote in
    > message news:...
    >> Just drag the control's DLL onto your toolbox.
    >>
    >> --
    >> I hope this helps,
    >> Steve C. Orr,
    >> MCSD, MVP, CSM, ASPInsider
    >> http://SteveOrr.net
    >>
    >>
    >> "John Kotuby" <> wrote in message
    >> news:%...
    >>> 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
    >>> -------------------------------------------
    >>>
    >>>

    >>
    >>

    >
    >
    >
     
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider], May 10, 2007
    #5
  6. John Kotuby

    John Kotuby Guest

    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

    "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]" <> wrote in
    message news:...
    > 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" <> wrote in message
    > news:%...
    >> 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 [MCSD, MVP, CSM, ASP Insider]" <> wrote in
    >> message news:...
    >>> Just drag the control's DLL onto your toolbox.
    >>>
    >>> --
    >>> I hope this helps,
    >>> Steve C. Orr,
    >>> MCSD, MVP, CSM, ASPInsider
    >>> http://SteveOrr.net
    >>>
    >>>
    >>> "John Kotuby" <> wrote in message
    >>> news:%...
    >>>> 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
    >>>> -------------------------------------------
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>
    >>

    >
    >
     
    John Kotuby, May 11, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Just Me
    Replies:
    3
    Views:
    620
    Coskun SUNALI [MVP]
    Dec 26, 2007
  2. dave

    Custom Control and Toolbox not working

    dave, Mar 30, 2006, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    140
    Wayne
    Apr 3, 2006
  3. PeterKellner

    Problem Getting Custom Control to show not greyed out in toolbox

    PeterKellner, May 23, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    176
    PeterKellner
    May 23, 2006
  4. C Townhill

    Cannot drag custom web control from toolbox

    C Townhill, Mar 22, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    285
    Steven Cheng[MSFT]
    Mar 24, 2005
  5. Brian Edwards

    Can't drag Web Custom Control from Toolbox onto Webform

    Brian Edwards, Nov 14, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    184
    Brian Edwards
    Nov 14, 2005
Loading...

Share This Page