Cannot add custom control to toolbox - why not?

Discussion in 'ASP .Net Web Controls' started by James Radke, Dec 18, 2003.

  1. James Radke

    James Radke Guest

    Hello,

    I am creating a custom vb.net web control. This control is a timer that
    will automatically postback to the server (see
    http://www.eggheadcafe.com/articles/20021006.asp for C# source that I am
    trying to translate to vb)

    Every time I try to add the control to the toolbox (using add/remove items
    then browsing to the DLL on my test web server) in a new web project I get
    an error which says that I cannot load the DLL, check the dependencies. I
    have no idea why this does not allow me add my custom control to the toolbox
    so that I can drag/drop it into my project.

    Can anyone help me out? I don't know what is going on.....

    The source code follows:

    Thanks!

    Jim

    ==== WebTimer.VB ========

    Imports System
    Imports System.IO
    Imports System.Drawing
    Imports System.Web
    Imports System.Web.UI
    Imports System.Web.UI.Design
    Imports System.Web.UI.WebControls
    Imports System.ComponentModel
    Imports System.ComponentModel.Design
    Imports System.Text

    Namespace Stratecon.Web

    <ToolboxDataAttribute("<{0}:WebTimer runat=""server""></{0}:WebTimer>"),
    _
    DefaultEventAttribute("Elapsed"), _
    ToolboxBitmapAttribute(GetType(Bitmap), "Stratecon.Web.WebTimer.bmp"),
    _
    DesignerAttribute("Stratecon.Web.TimerDesigner",
    "Stratecon.Web.Timer")> _
    Public Class Timer
    Inherits Control
    Implements IPostBackEventHandler

    Private iInterval As Integer = 5000
    Private bEnabled As Boolean = True
    Private bEnableViewState As Boolean = True
    Public Event Elapsed As EventHandler
    <BindableAttribute(True), _
    CategoryAttribute("WebTimer"), _
    DescriptionAttribute("Whether WebTimer Control is enabled."), _
    BrowsableAttribute(True)> _
    Public Property Enabled() As Boolean
    Get
    Return bEnabled
    End Get
    Set(ByVal Value As Boolean)
    bEnabled = Value
    End Set
    End Property

    <BindableAttribute(False), _
    BrowsableAttribute(False)> _
    Public Overrides Property EnableViewState() As Boolean
    Get
    Return bEnableViewState
    End Get
    Set(ByVal Value As Boolean)
    bEnableViewState = Value
    End Set
    End Property

    <CategoryAttribute("WebTimer"), _
    BrowsableAttribute(True), _
    DescriptionAttribute("Number of milliseconds WebTimer waits until
    firing a postback."), _
    BindableAttribute(True)> _
    Public Property Interval() As Integer
    Get
    Return iInterval
    End Get
    Set(ByVal Value As Integer)
    iInterval = Value
    End Set
    End Property

    Protected Overrides Sub OnInit(ByVal e As EventArgs)

    End Sub

    Public Sub RaisePostBackEvent(ByVal eventArgument As String) _
    Implements IPostBackEventHandler.RaisePostBackEvent
    OnElapsed(New EventArgs)
    End Sub

    Public Sub OnElapsed(ByVal ea As EventArgs)
    RaiseEvent Elapsed(Me, ea)
    End Sub

    Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
    If Enabled Then
    '* Create the Javascript postback "setTimeout" Page Timer
    code:
    '<script language="javascript">
    '<!--
    'setTimeout( "__doPostBack('PgTimer1','')", 5000);
    '// -->
    '</script>
    '*/
    Dim sb As New StringBuilder
    sb.Append("\n<script language=\""javascript\""> \n <!-- \n
    setTimeout( \")
    sb.Append(MyBase.Page.GetPostBackEventReference(Me))
    sb.Append("\n ,")
    sb.Append(iInterval.ToString())
    sb.Append("); \n // --> \n </script>")
    output.Write(sb.ToString())
    End If
    End Sub

    End Class

    End Namespace


    ==== webtimer.designer.vb =======

    Imports System
    Imports System.ComponentModel
    Imports System.ComponentModel.Design
    Imports System.Reflection
    Imports System.Web.UI.Design
    Imports System.Web.UI.WebControls
    Imports System.Web.UI
    Imports System.Web

    Namespace Stratecon.Web

    Public Class TimerDesigner
    Inherits System.Web.UI.Design.ControlDesigner

    Private webtimer As New Stratecon.Web.Timer

    Public Overrides Function GetDesignTimeHtml() As String
    Return "<label id=\'Lbl1\' style=\'align: center; COLOR:Blue;
    valign: middle; background-color:FFCC66; border-width:2px;\'
    >WebTimer</label>"

    End Function

    Public Overrides Sub Initialize(ByVal component As IComponent)
    webtimer = component
    MyBase.Initialize(component)
    End Sub
    End Class

    End Namespace
     
    James Radke, Dec 18, 2003
    #1
    1. Advertising

  2. Hi James,

    I will do some research for you. I will reply you ASAP.
    Thanks for your understanding.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Dec 19, 2003
    #2
    1. Advertising

  3. James Radke

    James Radke Guest

    Jeffrey,

    I figured out most of my issues, and the control is working well... except
    for one thing:

    The control I am building has no graphical interface, yet I would like the
    control to show up as a literal (or perhaps as an bitmap image) in the
    VS.NET 2003 designer so I can see it is on the page when I am modifying /
    building the page; and to make it easy to click on it and modify the
    properties.

    I thought the following code:

    Public Overrides Function GetDesignTimeHtml() As String
    Dim sw As New StringWriter
    Dim tw As New HtmlTextWriter(sw)

    Dim controllabel As New Label

    ' Put simple.Text into the link's Text.
    controllabel.Text = "WebTimer"
    controllabel.ForeColor = System.Drawing.Color.Blue
    controllabel.BackColor = System.Drawing.Color.Cornsilk
    controllabel.RenderControl(tw)

    Return sw.ToString()
    'Return "<span style='align: center; COLOR:Blue; valign: middle;
    background-color:FFCC66; border-width:2px;'>WebTimer</span>"
    End Function

    in the designer module would do that; yet, in the designer, my control
    always shows up as just the green arrow showing a control with some weird
    lines right next to it? How do I make it so that it either appears as a
    literal, or an image file?

    Thanks!

    Jim

    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    >
    > Hi James,
    >
    > I will do some research for you. I will reply you ASAP.
    > Thanks for your understanding.
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
     
    James Radke, Dec 19, 2003
    #3
  4. Hi James,

    I am glad that you worked out your original problem.
    For your following question, actually you can do customize UI in
    GetDesignTimeHtml.
    This MSDN article talks about this:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
    vbwlkWalkthroughCreatingCustomWebControls.asp

    Also another article provide you a good sample of design-time support of
    web form:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html
    /aspnet-adddesigntimesupport.asp

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Dec 22, 2003
    #4
  5. James Radke

    Jiho Han Guest

    James,

    What did you do to resolve your issue with the toolbox because I am having
    the same problem?

    Thanks much.

    "James Radke" <> wrote in message
    news:%...
    > Jeffrey,
    >
    > I figured out most of my issues, and the control is working well... except
    > for one thing:
    >
    > The control I am building has no graphical interface, yet I would like the
    > control to show up as a literal (or perhaps as an bitmap image) in the
    > VS.NET 2003 designer so I can see it is on the page when I am modifying /
    > building the page; and to make it easy to click on it and modify the
    > properties.
    >
    > I thought the following code:
    >
    > Public Overrides Function GetDesignTimeHtml() As String
    > Dim sw As New StringWriter
    > Dim tw As New HtmlTextWriter(sw)
    >
    > Dim controllabel As New Label
    >
    > ' Put simple.Text into the link's Text.
    > controllabel.Text = "WebTimer"
    > controllabel.ForeColor = System.Drawing.Color.Blue
    > controllabel.BackColor = System.Drawing.Color.Cornsilk
    > controllabel.RenderControl(tw)
    >
    > Return sw.ToString()
    > 'Return "<span style='align: center; COLOR:Blue; valign:

    middle;
    > background-color:FFCC66; border-width:2px;'>WebTimer</span>"
    > End Function
    >
    > in the designer module would do that; yet, in the designer, my control
    > always shows up as just the green arrow showing a control with some weird
    > lines right next to it? How do I make it so that it either appears as a
    > literal, or an image file?
    >
    > Thanks!
    >
    > Jim
    >
    > ""Jeffrey Tan[MSFT]"" <> wrote in message
    > news:...
    > >
    > > Hi James,
    > >
    > > I will do some research for you. I will reply you ASAP.
    > > Thanks for your understanding.
    > >
    > > Best regards,
    > > Jeffrey Tan
    > > Microsoft Online Partner Support
    > > Get Secure! - www.microsoft.com/security
    > > This posting is provided "as is" with no warranties and confers no

    rights.
    > >

    >
    >
     
    Jiho Han, Dec 22, 2003
    #5
  6. James Radke

    Jiho Han Guest

    @#$%!

    The only problem was that my .dll was located on a mapped drive(on the
    network) when I was trying to add to the toolbox.
    Once I moved it to a local folder, it added with no problem.

    Ironically, I ignore the warning message that popped up when I set my
    project folder to the mapped path - some security stuff and the project may
    not execute correctly due to the lack of full trust, blah blah. Goes to
    show that you should really heed the warning messages however trivial it
    seems at the moment...

    "Jiho Han" <> wrote in message
    news:...
    > James,
    >
    > What did you do to resolve your issue with the toolbox because I am having
    > the same problem?
    >
    > Thanks much.
    >
    > "James Radke" <> wrote in message
    > news:%...
    > > Jeffrey,
    > >
    > > I figured out most of my issues, and the control is working well...

    except
    > > for one thing:
    > >
    > > The control I am building has no graphical interface, yet I would like

    the
    > > control to show up as a literal (or perhaps as an bitmap image) in the
    > > VS.NET 2003 designer so I can see it is on the page when I am modifying

    /
    > > building the page; and to make it easy to click on it and modify the
    > > properties.
    > >
    > > I thought the following code:
    > >
    > > Public Overrides Function GetDesignTimeHtml() As String
    > > Dim sw As New StringWriter
    > > Dim tw As New HtmlTextWriter(sw)
    > >
    > > Dim controllabel As New Label
    > >
    > > ' Put simple.Text into the link's Text.
    > > controllabel.Text = "WebTimer"
    > > controllabel.ForeColor = System.Drawing.Color.Blue
    > > controllabel.BackColor = System.Drawing.Color.Cornsilk
    > > controllabel.RenderControl(tw)
    > >
    > > Return sw.ToString()
    > > 'Return "<span style='align: center; COLOR:Blue; valign:

    > middle;
    > > background-color:FFCC66; border-width:2px;'>WebTimer</span>"
    > > End Function
    > >
    > > in the designer module would do that; yet, in the designer, my control
    > > always shows up as just the green arrow showing a control with some

    weird
    > > lines right next to it? How do I make it so that it either appears as a
    > > literal, or an image file?
    > >
    > > Thanks!
    > >
    > > Jim
    > >
    > > ""Jeffrey Tan[MSFT]"" <> wrote in message
    > > news:...
    > > >
    > > > Hi James,
    > > >
    > > > I will do some research for you. I will reply you ASAP.
    > > > Thanks for your understanding.
    > > >
    > > > Best regards,
    > > > Jeffrey Tan
    > > > Microsoft Online Partner Support
    > > > Get Secure! - www.microsoft.com/security
    > > > This posting is provided "as is" with no warranties and confers no

    > rights.
    > > >

    > >
    > >

    >
    >
     
    Jiho Han, Dec 22, 2003
    #6
  7. James Radke

    James Radke Guest

    Jiho,

    I had to laugh because that is the same exact issue I was having! Since I
    don't have a local webserver I am using a remote one for testing, and it
    never occurred to me (at first) that I couldn't simply reference the remote
    BIN directory....

    Just goes to show you that is is always the simple things that get you.....
    :)

    Glad you figured it out!

    Jim

    "Jiho Han" <> wrote in message
    news:...
    > @#$%!
    >
    > The only problem was that my .dll was located on a mapped drive(on the
    > network) when I was trying to add to the toolbox.
    > Once I moved it to a local folder, it added with no problem.
    >
    > Ironically, I ignore the warning message that popped up when I set my
    > project folder to the mapped path - some security stuff and the project

    may
    > not execute correctly due to the lack of full trust, blah blah. Goes to
    > show that you should really heed the warning messages however trivial it
    > seems at the moment...
    >
    > "Jiho Han" <> wrote in message
    > news:...
    > > James,
    > >
    > > What did you do to resolve your issue with the toolbox because I am

    having
    > > the same problem?
    > >
    > > Thanks much.
    > >
    > > "James Radke" <> wrote in message
    > > news:%...
    > > > Jeffrey,
    > > >
    > > > I figured out most of my issues, and the control is working well...

    > except
    > > > for one thing:
    > > >
    > > > The control I am building has no graphical interface, yet I would like

    > the
    > > > control to show up as a literal (or perhaps as an bitmap image) in the
    > > > VS.NET 2003 designer so I can see it is on the page when I am

    modifying
    > /
    > > > building the page; and to make it easy to click on it and modify the
    > > > properties.
    > > >
    > > > I thought the following code:
    > > >
    > > > Public Overrides Function GetDesignTimeHtml() As String
    > > > Dim sw As New StringWriter
    > > > Dim tw As New HtmlTextWriter(sw)
    > > >
    > > > Dim controllabel As New Label
    > > >
    > > > ' Put simple.Text into the link's Text.
    > > > controllabel.Text = "WebTimer"
    > > > controllabel.ForeColor = System.Drawing.Color.Blue
    > > > controllabel.BackColor = System.Drawing.Color.Cornsilk
    > > > controllabel.RenderControl(tw)
    > > >
    > > > Return sw.ToString()
    > > > 'Return "<span style='align: center; COLOR:Blue; valign:

    > > middle;
    > > > background-color:FFCC66; border-width:2px;'>WebTimer</span>"
    > > > End Function
    > > >
    > > > in the designer module would do that; yet, in the designer, my control
    > > > always shows up as just the green arrow showing a control with some

    > weird
    > > > lines right next to it? How do I make it so that it either appears as

    a
    > > > literal, or an image file?
    > > >
    > > > Thanks!
    > > >
    > > > Jim
    > > >
    > > > ""Jeffrey Tan[MSFT]"" <> wrote in message
    > > > news:...
    > > > >
    > > > > Hi James,
    > > > >
    > > > > I will do some research for you. I will reply you ASAP.
    > > > > Thanks for your understanding.
    > > > >
    > > > > Best regards,
    > > > > Jeffrey Tan
    > > > > Microsoft Online Partner Support
    > > > > Get Secure! - www.microsoft.com/security
    > > > > This posting is provided "as is" with no warranties and confers no

    > > rights.
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    James Radke, Dec 23, 2003
    #7
    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. Prasanna Padmanabhan

    add custom control to toolbox

    Prasanna Padmanabhan, Jul 3, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    3,676
    Prasanna Padmanabhan
    Jul 3, 2003
  2. tom c
    Replies:
    1
    Views:
    1,563
    Jon Paal
    Sep 7, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,260
    Smokey Grindel
    Dec 2, 2006
  4. Jeff
    Replies:
    1
    Views:
    450
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Dec 17, 2006
  5. C Townhill

    Cannot drag custom web control from toolbox

    C Townhill, Mar 22, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    287
    Steven Cheng[MSFT]
    Mar 24, 2005
Loading...

Share This Page