Web Custom Control having error on ID field

S

Steve Mauldin

I get the following error when trying to view in browser an aspx page that
has my simple Web Custom Control. If I remove the ID=Controlname from the
ASPX then the page and control displays correctly but I need to have id
fields to reference my web custom controls in code behind. Can someone tell
me what I maybe doing wrong to cause this error? I have included the Error
message, the web custom control code, the ASPX code, and the command line I
used to compile the Web Custom Control. Any help would be greatly
appreciated.
Thank you,

Steve Mauldin

<<<Error Message>>>

Server Error in '/Webtesting' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.
Parser Error Message: The base class includes the field 'ShowGreen1', but
its type (Webtesting.myControls.ShowGreen) is not compatible with the type
of control (Webtesting.myControls.ShowGreen).
Source Error:
Line 6: </HEAD>
Line 7: <body>
Line 8: <mycontrols:showgreen id="ShowGreen1" Runat="server">Hello
World!</mycontrols:showgreen>
Line 9: </body>
Line 10: </HTML>
Source File: c:\inetpub\wwwroot\Webtesting\DisplayShowGreen.aspx Line: 8
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
Version:1.1.4322.573

<<<Web Custom Control Code>>>

Imports System
Imports System.Web
Imports System.Web.UI
Namespace myControls
Public Class ShowGreen : Inherits Control
Protected Overrides Sub Render(ByVal objTextWriter As HtmlTextWriter)
Dim strInnerText As String
If IsLiteralContent Then
strInnerText = CType(Controls(0), LiteralControl).Text
objTextWriter.AddAttribute("color", "green")
objTextWriter.RenderBeginTag("font")
objTextWriter.RenderBeginTag("b")
objTextWriter.Write(strInnerText)
objTextWriter.RenderEndTag()
objTextWriter.RenderEndTag()
End If
End Sub
End Class
End Namespace

<<<ASPX Code>>>

<%@ Register TagPrefix="myControls" Namespace="Webtesting.myControls"
Assembly="ShowGreen"%>
<%@ Page CodeBehind="DisplayShowGreen.aspx.vb" Language="vb"
AutoEventWireup="false" Inherits="Webtesting.DisplayShowGreen" %>
<HTML>
<HEAD>
<title>DisplayShowGreen.aspx</title>
</HEAD>
<body>
<myControls:showgreen id="ShowGreen1" Runat="server">Hello
World!</myControls:showgreen>
</body>
</HTML>

<<<Command Line Code>>>

C:\inetpub\wwwroot\Webtesting>vbc /t:library /rootnamespace:Webtesting
/r:system.dll,system.web.dll ShowGreen.vb
 
S

Steve Mauldin

Scott,
I am new to .net and am following an example in the book I have and I have
compiled the custom control, placed the resulting dll into my projects bin
directory, added the custom control to my tool bar and dragged and dropped
it onto the clean ASPX page. The resulting ASPX file has the ID that the
framework assigned the control but I get the error when I try "view in
browser" on the ASPX Page. If I memove the framework added ID field then I
do not get any error. but I need the Id field to do code behind work for
what I want to do with the control. I plan to set control properties in the
code behind and I need to give the control a name in order to achieve that.

P.S. Thank you for your response.
 
M

Mythran

Scott Simes said:
It's not clear how you'll be using your control, whether it will be in a
panel or on the main page, etc., but in general let the framework assign
your ID and then locate your control using the "FindControl" method.

I've had this error before. We've discovered that .Net is trippin' when it comes
to exceptions like these :p Anywho, can't remember how we fixed it (unless we
just bypassed the exception as you can do by removing the id).

Just in case, there aren't 2 of these controls on the same form right? Nor are
there more than 1 reference to the library?

Have to ask (you CAN have more than 1 reference to the same library....I found
that out the hard way...project ref, file ref..et cetera).

Mythran
 
M

Mythran

If the control isn't that large, mind posting the control's code-behind...I wanna
make sure it's not the control's code that's causing the exception...

Mythran
 
S

Steve Mauldin

Mythran,
Only one reference in the Library and only the one control on the page. I
kept it as simple as possible to eliminate those types of problems.

Thank you for your response.

Steve Mauldin
 
S

Steve Mauldin

Mythran,
There currently is no code behind code. I posted everything I have code
wise. I have not even go to tcoding up the code behind because I hit this
issue right off the bat.
 
S

Steve Mauldin

Scott,

I have done all that and it still happening. Also every example off the cd
from the book ASP.Net Unleashed second edition also have the same problem.
Have you tried taking the code I posted to see if you get the same error? I
am running the latest version of .NET. Could this be something settings
wise that is causing this?
 
S

Steve Mauldin

For anyone who reads this looking for an answer, here is what fixed it for
me.
I was using the Web Custom Controls examples in "ASP.NET Unleashed from
SAMS". These examples did not work because I brought the examples into a
ASP.Net Web Application and it should have been a Web Control Library. I
found a great Step By step example in "Microsoft ASP.NET Programming with
Microsoft Visual Basic.net step by step". Check out Chapter 10 Creating
Custom Server Controls.
 
S

Steve Mauldin

Mythran,
All the code is on the original post. I found out the problem. I was
compiling the Web Custom Control in a ASP.Net Web Application. I found an
example that had almost the same code as mine but it used a Web Control
Library. I used that example and everything works fine. There must be
something in the command line compile I was doing that was slightly off and
not allowing it to run with an assigned ID field but it would run without
one. Thank you for your help.
Steve Mauldin
 
S

Steve Mauldin

Scott,
I was using the Web Custom Controls examples in "ASP.NET Unleashed from
SAMS". These examples did not work because I brought the examples into a
ASP.Net Web Application and it should have been a Web Control Library. I
found a great Step By step example in "Microsoft ASP.NET Programming with
Microsoft Visual Basic.net step by step". Check out Chapter 10 Creating
Custom Server Controls. Thanks for your help.

Steve Mauldin
 

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,816
Latest member
SapanaCarpetStudio

Latest Threads

Top