Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Web Custom Control having error on ID field (http://www.velocityreviews.com/forums/t773902-web-custom-control-having-error-on-id-field.html)

Steve Mauldin 07-28-2004 03:23 PM

Web Custom Control having error on ID field
 
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.asp x 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



Steve Mauldin 07-28-2004 03:49 PM

Re: Web Custom Control having error on ID field
 
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.

"Scott Simes" <usa_NO8SPAM004@yahoo.com> wrote in message
news:ZMPNc.37354$WP1.34117@fe1.texas.rr.com...
> 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.
>
>




Mythran 07-28-2004 03:50 PM

Re: Web Custom Control having error on ID field
 

"Scott Simes" <usa_NO8SPAM004@yahoo.com> wrote in message
news:ZMPNc.37354$WP1.34117@fe1.texas.rr.com...
> 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



Mythran 07-28-2004 03:56 PM

Re: Web Custom Control having error on ID field
 
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

"Steve Mauldin" <stevemauldin@hotmail.com> wrote in message
news:eF5S%23pLdEHA.3528@TK2MSFTNGP12.phx.gbl...
> 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.
>
> "Scott Simes" <usa_NO8SPAM004@yahoo.com> wrote in message
> news:ZMPNc.37354$WP1.34117@fe1.texas.rr.com...
> > 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.
> >
> >

>
>




Steve Mauldin 07-28-2004 03:56 PM

Re: Web Custom Control having error on ID field
 
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

"Mythran" <kip_potter@hotmail.com> wrote in message
news:%23ix2dqLdEHA.712@TK2MSFTNGP09.phx.gbl...
>
> "Scott Simes" <usa_NO8SPAM004@yahoo.com> wrote in message
> news:ZMPNc.37354$WP1.34117@fe1.texas.rr.com...
> > 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
>
>




Steve Mauldin 07-28-2004 04:18 PM

Re: Web Custom Control having error on ID field
 
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.


"Mythran" <kip_potter@hotmail.com> wrote in message
news:%23Ub8utLdEHA.3476@tk2msftngp13.phx.gbl...
> 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
>
> "Steve Mauldin" <stevemauldin@hotmail.com> wrote in message
> news:eF5S%23pLdEHA.3528@TK2MSFTNGP12.phx.gbl...
> > 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.
> >
> > "Scott Simes" <usa_NO8SPAM004@yahoo.com> wrote in message
> > news:ZMPNc.37354$WP1.34117@fe1.texas.rr.com...
> > > 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.
> > >
> > >

> >
> >

>
>




Steve Mauldin 07-28-2004 04:22 PM

Re: Web Custom Control having error on ID field
 
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?


"Scott Simes" <usa_NO8SPAM004@yahoo.com> wrote in message
news:ZdQNc.42306$pR5.4748@fe2.texas.rr.com...
> Is it possible your DLL is not actually the version you think it is? Try
> removing the reference to your DLL and also removing the control from the
> Toolbox--then re-add the DLL by browsing to the SAME DLL that you have

just
> compiled (check the date/time stamp). After, add the item back to the
> toolbox. Then start with a fresh aspx document and drag-and-drop a new
> control instance and see what happens...
>
>




Steve Mauldin 07-28-2004 09:09 PM

Re: Web Custom Control having error on ID field
 
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.

"Steve Mauldin" <stevemauldin@hotmail.com> wrote in message
news:OYucibLdEHA.4048@TK2MSFTNGP12.phx.gbl...
> 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.asp x 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
>
>




Steve Mauldin 07-29-2004 04:57 PM

Re: Web Custom Control having error on ID field
 
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

"Mythran" <kip_potter@hotmail.com> wrote in message
news:%23Ub8utLdEHA.3476@tk2msftngp13.phx.gbl...
> 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
>
> "Steve Mauldin" <stevemauldin@hotmail.com> wrote in message
> news:eF5S%23pLdEHA.3528@TK2MSFTNGP12.phx.gbl...
> > 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.
> >
> > "Scott Simes" <usa_NO8SPAM004@yahoo.com> wrote in message
> > news:ZMPNc.37354$WP1.34117@fe1.texas.rr.com...
> > > 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.
> > >
> > >

> >
> >

>
>




Steve Mauldin 07-29-2004 05:01 PM

Re: Web Custom Control having error on ID field
 
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

"Scott Simes" <usa_NO8SPAM004@yahoo.com> wrote in message
news:ZdQNc.42306$pR5.4748@fe2.texas.rr.com...
> Is it possible your DLL is not actually the version you think it is? Try
> removing the reference to your DLL and also removing the control from the
> Toolbox--then re-add the DLL by browsing to the SAME DLL that you have

just
> compiled (check the date/time stamp). After, add the item back to the
> toolbox. Then start with a fresh aspx document and drag-and-drop a new
> control instance and see what happens...
>
>





All times are GMT. The time now is 11:18 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.