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;\'
Public Overrides Sub Initialize(ByVal component As IComponent)
webtimer = component
MyBase.Initialize(component)
End Sub
End Class
End Namespace
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;\'
End FunctionWebTimer</label>"
Public Overrides Sub Initialize(ByVal component As IComponent)
webtimer = component
MyBase.Initialize(component)
End Sub
End Class
End Namespace