Web Custom Control having error on ID field

Discussion in 'ASP .Net Web Controls' started by Steve Mauldin, Jul 28, 2004.

  1. 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
     
    Steve Mauldin, Jul 28, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:ZMPNc.37354$...
    > 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, Jul 28, 2004
    #2
    1. Advertising

  3. Steve Mauldin

    Mythran Guest

    "Scott Simes" <> wrote in message
    news:ZMPNc.37354$...
    > 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, Jul 28, 2004
    #3
  4. Steve Mauldin

    Mythran Guest

    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" <> wrote in message
    news:eF5S%...
    > 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" <> wrote in message
    > news:ZMPNc.37354$...
    > > 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, Jul 28, 2004
    #4
  5. 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" <> wrote in message
    news:%...
    >
    > "Scott Simes" <> wrote in message
    > news:ZMPNc.37354$...
    > > 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, Jul 28, 2004
    #5
  6. 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" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:eF5S%...
    > > 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" <> wrote in message
    > > news:ZMPNc.37354$...
    > > > 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, Jul 28, 2004
    #6
  7. 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" <> wrote in message
    news:ZdQNc.42306$...
    > 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, Jul 28, 2004
    #7
  8. 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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Steve Mauldin, Jul 28, 2004
    #8
  9. 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" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:eF5S%...
    > > 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" <> wrote in message
    > > news:ZMPNc.37354$...
    > > > 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, Jul 29, 2004
    #9
  10. 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" <> wrote in message
    news:ZdQNc.42306$...
    > 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, Jul 29, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Sokol
    Replies:
    2
    Views:
    409
    Theo Tillotson
    Aug 7, 2003
  2. Steve Mauldin

    Web Custom Control error on ID field

    Steve Mauldin, Jul 28, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    118
  3. Deniz Miscioglu
    Replies:
    1
    Views:
    172
    Deniz Miscioglu
    Oct 19, 2003
  4. Sound
    Replies:
    2
    Views:
    465
    Randy Webb
    Sep 28, 2006
  5. jr
    Replies:
    3
    Views:
    450
Loading...

Share This Page