Cannot add custom control to toolbox - why not?

J

James Radke

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
 
J

Jeffrey Tan[MSFT]

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

James Radke

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
 
J

Jeffrey Tan[MSFT]

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

Jiho Han

James,

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

Thanks much.

James Radke said:
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]" said:
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.
 
J

Jiho Han

@#$%!

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 said:
James,

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

Thanks much.

James Radke said:
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]" said:
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.
 
J

James Radke

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
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top