A
Andy R
I have been working with one of the examples from the MSDN library to provide
an onclick() event for a custom control using visual basic.net
I have compiled the custom control code below to create a customcontrols.dll
and copied it to the root /bin project folder:-
Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace CustomControls
Public Class MyButton
Inherits Control
Implements IPostBackEventHandler
' Defines the Click event.
Public Event Click As EventHandler
' Invokes delegates registered with the Click event.
Protected Overridable Sub OnClick(ByVal e As EventArgs)
RaiseEvent Click(Me, e)
End Sub
' Method of IPostBackEventHandler that raises change events.
Public Sub RaisePostBackEvent(ByVal eventArgument As String)
Implements IPostBackEventHandler.RaisePostBackEvent
OnClick(EventArgs.Empty)
End Sub
Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
output.Write("<INPUT TYPE=submit name=" & Me.UniqueID & _
" Value='Click Me' />")
End Sub
End Class
End Namespace
The following ASPX code should then utlise the customcontrols.dll
<%@ Register TagPrefix="Custom" Namespace="CustomControls" Assembly =
"CustomControls" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb"
Inherits="WebDataReader.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="VB" runat="server">
Private Sub Button_Click(sender As Object, e As EventArgs)
TextBox.BackColor = System.Drawing.Color.Green
TextBox.Text = "You clicked the button"
End Sub
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<Custom:MyButton id="Mybutton1" onclick="Button_Click"
runat="server">Hello</><br>
<asp:textbox id="Textbox1" runat="server" BackColor="Cyan" Width="200"
Text="Click the button"></asp:textbox><br>
</form>
</body>
</HTML>
I am getting:-
Parser Error Message: Could not load type CustomControls.MyButton from
assembly CustomControls, Version=1.0.1833.24970, Culture=neutral,
PublicKeyToken=null.
This referrs to the line:
<Custom:MyButton id="Mybutton1" onclick="Button_Click"
runat="server">Hello</><br>
Can anybody shed some light on what I may be doing wrong?
an onclick() event for a custom control using visual basic.net
I have compiled the custom control code below to create a customcontrols.dll
and copied it to the root /bin project folder:-
Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace CustomControls
Public Class MyButton
Inherits Control
Implements IPostBackEventHandler
' Defines the Click event.
Public Event Click As EventHandler
' Invokes delegates registered with the Click event.
Protected Overridable Sub OnClick(ByVal e As EventArgs)
RaiseEvent Click(Me, e)
End Sub
' Method of IPostBackEventHandler that raises change events.
Public Sub RaisePostBackEvent(ByVal eventArgument As String)
Implements IPostBackEventHandler.RaisePostBackEvent
OnClick(EventArgs.Empty)
End Sub
Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
output.Write("<INPUT TYPE=submit name=" & Me.UniqueID & _
" Value='Click Me' />")
End Sub
End Class
End Namespace
The following ASPX code should then utlise the customcontrols.dll
<%@ Register TagPrefix="Custom" Namespace="CustomControls" Assembly =
"CustomControls" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb"
Inherits="WebDataReader.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="VB" runat="server">
Private Sub Button_Click(sender As Object, e As EventArgs)
TextBox.BackColor = System.Drawing.Color.Green
TextBox.Text = "You clicked the button"
End Sub
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<Custom:MyButton id="Mybutton1" onclick="Button_Click"
runat="server">Hello</><br>
<asp:textbox id="Textbox1" runat="server" BackColor="Cyan" Width="200"
Text="Click the button"></asp:textbox><br>
</form>
</body>
</HTML>
I am getting:-
Parser Error Message: Could not load type CustomControls.MyButton from
assembly CustomControls, Version=1.0.1833.24970, Culture=neutral,
PublicKeyToken=null.
This referrs to the line:
<Custom:MyButton id="Mybutton1" onclick="Button_Click"
runat="server">Hello</><br>
Can anybody shed some light on what I may be doing wrong?