Custom Controls Example (Parser Error)

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?
 
M

Mike MacMillan

Andy,
what its telling you is that the MyButton class doesn't exist in the
namespace you've specified in the
<% register.. %> tag in the header. either a) you didn't qualify the
namespace correctly or b) perhaps the control you need to reference is a
user control instead (.ascx file).

Mike
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top