Accessing a usercontrol from parent codebehind

Discussion in 'ASP .Net' started by Mat, Oct 28, 2004.

  1. Mat

    Mat Guest

    Hi,

    I am having a bit of a problem trying to access / set properties of a
    usercontrol from the parent codebehind.

    This is what I have so far..

    simple.aspx
    <%@ Page Inherits="CodeBehindSimple" src="simple.vb" %>
    <%@ Register TagPrefix="CC" TagName="Simple" Src="ucSimple.ascx"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
    "http://www.w3.org/TR/REC-html40/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <title></title>
    </head>
    <body>

    <form runat="server">

    <CC:Simple id="mySimple" myParam="Hello from aspx" runat="server" />

    </form>

    </body>
    </html>

    simple.vb
    Imports System
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.HtmlControls

    Public Class CodeBehindSimple
    Inherits Page

    Protected WithEvents mySimple As Simple

    sub Page_Load
    mySimple.myParam = "Hello from codebehind"
    end sub
    End Class

    ucSimple.ascx
    <%@ Control Language="VB" Inherits="mySimpleNS.Simple"
    src="./ucSimple.vb"%>


    <asp:Label id="lbl_Simple" runat="server" />[/code]

    ucSimple.vb

    Imports System
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.HtmlControls

    Namespace mySimpleNS

    Public Class Simple
    Inherits UserControl

    Protected WithEvents lbl_Simple as Label

    public property myParam as string
    get
    return lbl_Simple.text
    end get
    set
    lbl_Simple.text = value
    end set
    end property

    End Class

    End Namespace

    What should happen is that the parent codebehind (simple.vb) should
    update the usercontrol CC:Simple "myParam" with "Hello from
    codebehind". This dont happen, I get an error:

    BC30002: Type 'Simple' is not defined.

    If I comment out (in simple.vb)
    'Protected WithEvents mySimple As Simple

    'sub Page_Load
    ' mySimple.myParam = "Hello from codebehind"
    'end sub

    I get the text set in the parent (simple.aspx) output.

    Anyone got any ideas? BTW I am not using VS.Net.

    Cheers.
     
    Mat, Oct 28, 2004
    #1
    1. Advertising

  2. Mat

    Saravana Guest

    Instead of declaring
    Protected WithEvents mySimple As Simple

    declare with namespace, like this
    Protected WithEvents mySimple As mySimpleNS.Simple

    I think that is the issue

    --
    Saravana
    http://dotnetjunkies.com/WebLog/saravana/
    www.ExtremeExperts.com


    "Mat" <> wrote in message
    news:...
    > Hi,
    >
    > I am having a bit of a problem trying to access / set properties of a
    > usercontrol from the parent codebehind.
    >
    > This is what I have so far..
    >
    > simple.aspx
    > <%@ Page Inherits="CodeBehindSimple" src="simple.vb" %>
    > <%@ Register TagPrefix="CC" TagName="Simple" Src="ucSimple.ascx"%>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
    > "http://www.w3.org/TR/REC-html40/strict.dtd">
    > <html>
    > <head>
    > <meta http-equiv="Content-Type" content="text/html;
    > charset=iso-8859-1">
    > <title></title>
    > </head>
    > <body>
    >
    > <form runat="server">
    >
    > <CC:Simple id="mySimple" myParam="Hello from aspx" runat="server" />
    >
    > </form>
    >
    > </body>
    > </html>
    >
    > simple.vb
    > Imports System
    > Imports System.Web.UI
    > Imports System.Web.UI.WebControls
    > Imports System.Web.UI.HtmlControls
    >
    > Public Class CodeBehindSimple
    > Inherits Page
    >
    > Protected WithEvents mySimple As Simple
    >
    > sub Page_Load
    > mySimple.myParam = "Hello from codebehind"
    > end sub
    > End Class
    >
    > ucSimple.ascx
    > <%@ Control Language="VB" Inherits="mySimpleNS.Simple"
    > src="./ucSimple.vb"%>
    >
    >
    > <asp:Label id="lbl_Simple" runat="server" />[/code]
    >
    > ucSimple.vb
    >
    > Imports System
    > Imports System.Web.UI
    > Imports System.Web.UI.WebControls
    > Imports System.Web.UI.HtmlControls
    >
    > Namespace mySimpleNS
    >
    > Public Class Simple
    > Inherits UserControl
    >
    > Protected WithEvents lbl_Simple as Label
    >
    > public property myParam as string
    > get
    > return lbl_Simple.text
    > end get
    > set
    > lbl_Simple.text = value
    > end set
    > end property
    >
    > End Class
    >
    > End Namespace
    >
    > What should happen is that the parent codebehind (simple.vb) should
    > update the usercontrol CC:Simple "myParam" with "Hello from
    > codebehind". This dont happen, I get an error:
    >
    > BC30002: Type 'Simple' is not defined.
    >
    > If I comment out (in simple.vb)
    > 'Protected WithEvents mySimple As Simple
    >
    > 'sub Page_Load
    > ' mySimple.myParam = "Hello from codebehind"
    > 'end sub
    >
    > I get the text set in the parent (simple.aspx) output.
    >
    > Anyone got any ideas? BTW I am not using VS.Net.
    >
    > Cheers.
     
    Saravana, Oct 28, 2004
    #2
    1. Advertising

  3. Mat

    Mat Guest

    Nope, didnt fix it. I now get

    BC30002: Type 'mySimpleNS.Simple' is not defined

    Cheers,
    Mat.

    "Saravana" <> wrote in message news:<rA3gd.1764$>...
    > Instead of declaring
    > Protected WithEvents mySimple As Simple
    >
    > declare with namespace, like this
    > Protected WithEvents mySimple As mySimpleNS.Simple
    >
    > I think that is the issue
    >
    > --
    > Saravana
    > http://dotnetjunkies.com/WebLog/saravana/
    > www.ExtremeExperts.com
    >
    >
    > "Mat" <> wrote in message
    > news:...
    > > Hi,
    > >
    > > I am having a bit of a problem trying to access / set properties of a
    > > usercontrol from the parent codebehind.
    > >
    > > This is what I have so far..
    > >
    > > simple.aspx
    > > <%@ Page Inherits="CodeBehindSimple" src="simple.vb" %>
    > > <%@ Register TagPrefix="CC" TagName="Simple" Src="ucSimple.ascx"%>
    > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
    > > "http://www.w3.org/TR/REC-html40/strict.dtd">
    > > <html>
    > > <head>
    > > <meta http-equiv="Content-Type" content="text/html;
    > > charset=iso-8859-1">
    > > <title></title>
    > > </head>
    > > <body>
    > >
    > > <form runat="server">
    > >
    > > <CC:Simple id="mySimple" myParam="Hello from aspx" runat="server" />
    > >
    > > </form>
    > >
    > > </body>
    > > </html>
    > >
    > > simple.vb
    > > Imports System
    > > Imports System.Web.UI
    > > Imports System.Web.UI.WebControls
    > > Imports System.Web.UI.HtmlControls
    > >
    > > Public Class CodeBehindSimple
    > > Inherits Page
    > >
    > > Protected WithEvents mySimple As Simple
    > >
    > > sub Page_Load
    > > mySimple.myParam = "Hello from codebehind"
    > > end sub
    > > End Class
    > >
    > > ucSimple.ascx
    > > <%@ Control Language="VB" Inherits="mySimpleNS.Simple"
    > > src="./ucSimple.vb"%>
    > >
    > >
    > > <asp:Label id="lbl_Simple" runat="server" />[/code]
    > >
    > > ucSimple.vb
    > >
    > > Imports System
    > > Imports System.Web.UI
    > > Imports System.Web.UI.WebControls
    > > Imports System.Web.UI.HtmlControls
    > >
    > > Namespace mySimpleNS
    > >
    > > Public Class Simple
    > > Inherits UserControl
    > >
    > > Protected WithEvents lbl_Simple as Label
    > >
    > > public property myParam as string
    > > get
    > > return lbl_Simple.text
    > > end get
    > > set
    > > lbl_Simple.text = value
    > > end set
    > > end property
    > >
    > > End Class
    > >
    > > End Namespace
    > >
    > > What should happen is that the parent codebehind (simple.vb) should
    > > update the usercontrol CC:Simple "myParam" with "Hello from
    > > codebehind". This dont happen, I get an error:
    > >
    > > BC30002: Type 'Simple' is not defined.
    > >
    > > If I comment out (in simple.vb)
    > > 'Protected WithEvents mySimple As Simple
    > >
    > > 'sub Page_Load
    > > ' mySimple.myParam = "Hello from codebehind"
    > > 'end sub
    > >
    > > I get the text set in the parent (simple.aspx) output.
    > >
    > > Anyone got any ideas? BTW I am not using VS.Net.
    > >
    > > Cheers.
     
    Mat, Oct 28, 2004
    #3
  4. Mat

    Saravana Guest

    Add Reference to ucsimple.dll when you are compiling your codebehind.

    --
    Saravana
    http://dotnetjunkies.com/WebLog/saravana/
    www.ExtremeExperts.com


    "Mat" <> wrote in message
    news:...
    > Nope, didnt fix it. I now get
    >
    > BC30002: Type 'mySimpleNS.Simple' is not defined
    >
    > Cheers,
    > Mat.
    >
    > "Saravana" <> wrote in message

    news:<rA3gd.1764$>...
    > > Instead of declaring
    > > Protected WithEvents mySimple As Simple
    > >
    > > declare with namespace, like this
    > > Protected WithEvents mySimple As mySimpleNS.Simple
    > >
    > > I think that is the issue
    > >
    > > --
    > > Saravana
    > > http://dotnetjunkies.com/WebLog/saravana/
    > > www.ExtremeExperts.com
    > >
    > >
    > > "Mat" <> wrote in message
    > > news:...
    > > > Hi,
    > > >
    > > > I am having a bit of a problem trying to access / set properties of a
    > > > usercontrol from the parent codebehind.
    > > >
    > > > This is what I have so far..
    > > >
    > > > simple.aspx
    > > > <%@ Page Inherits="CodeBehindSimple" src="simple.vb" %>
    > > > <%@ Register TagPrefix="CC" TagName="Simple" Src="ucSimple.ascx"%>
    > > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
    > > > "http://www.w3.org/TR/REC-html40/strict.dtd">
    > > > <html>
    > > > <head>
    > > > <meta http-equiv="Content-Type" content="text/html;
    > > > charset=iso-8859-1">
    > > > <title></title>
    > > > </head>
    > > > <body>
    > > >
    > > > <form runat="server">
    > > >
    > > > <CC:Simple id="mySimple" myParam="Hello from aspx" runat="server" />
    > > >
    > > > </form>
    > > >
    > > > </body>
    > > > </html>
    > > >
    > > > simple.vb
    > > > Imports System
    > > > Imports System.Web.UI
    > > > Imports System.Web.UI.WebControls
    > > > Imports System.Web.UI.HtmlControls
    > > >
    > > > Public Class CodeBehindSimple
    > > > Inherits Page
    > > >
    > > > Protected WithEvents mySimple As Simple
    > > >
    > > > sub Page_Load
    > > > mySimple.myParam = "Hello from codebehind"
    > > > end sub
    > > > End Class
    > > >
    > > > ucSimple.ascx
    > > > <%@ Control Language="VB" Inherits="mySimpleNS.Simple"
    > > > src="./ucSimple.vb"%>
    > > >
    > > >
    > > > <asp:Label id="lbl_Simple" runat="server" />[/code]
    > > >
    > > > ucSimple.vb
    > > >
    > > > Imports System
    > > > Imports System.Web.UI
    > > > Imports System.Web.UI.WebControls
    > > > Imports System.Web.UI.HtmlControls
    > > >
    > > > Namespace mySimpleNS
    > > >
    > > > Public Class Simple
    > > > Inherits UserControl
    > > >
    > > > Protected WithEvents lbl_Simple as Label
    > > >
    > > > public property myParam as string
    > > > get
    > > > return lbl_Simple.text
    > > > end get
    > > > set
    > > > lbl_Simple.text = value
    > > > end set
    > > > end property
    > > >
    > > > End Class
    > > >
    > > > End Namespace
    > > >
    > > > What should happen is that the parent codebehind (simple.vb) should
    > > > update the usercontrol CC:Simple "myParam" with "Hello from
    > > > codebehind". This dont happen, I get an error:
    > > >
    > > > BC30002: Type 'Simple' is not defined.
    > > >
    > > > If I comment out (in simple.vb)
    > > > 'Protected WithEvents mySimple As Simple
    > > >
    > > > 'sub Page_Load
    > > > ' mySimple.myParam = "Hello from codebehind"
    > > > 'end sub
    > > >
    > > > I get the text set in the parent (simple.aspx) output.
    > > >
    > > > Anyone got any ideas? BTW I am not using VS.Net.
    > > >
    > > > Cheers.
     
    Saravana, Oct 29, 2004
    #4
  5. Mat

    Mat Guest

    Something just hit home... I am not compiling the codebehind for the
    usercontrol. This is probably why this is not working. What I am
    trying to achieve is possibly not possilble within the realms of a
    usercontrol.

    From my readings (correct me if I am wrong), a usercontrol is an
    uncompiled control, once compiled it is then considered a
    servercontrol.

    Do you think that what I am attempting to achieve in an uncompiled
    state is possible?

    Cheers for ALL your help, I owe you a virtual beer!
    Mat.

    "Saravana" <> wrote in message news:<fIigd.1874$>...
    > Add Reference to ucsimple.dll when you are compiling your codebehind.
    >
    > --
    > Saravana
    > http://dotnetjunkies.com/WebLog/saravana/
    > www.ExtremeExperts.com
    >
    >
    > "Mat" <> wrote in message
    > news:...
    > > Nope, didnt fix it. I now get
    > >
    > > BC30002: Type 'mySimpleNS.Simple' is not defined
    > >
    > > Cheers,
    > > Mat.
    > >
    > > "Saravana" <> wrote in message

    > news:<rA3gd.1764$>...
    > > > Instead of declaring
    > > > Protected WithEvents mySimple As Simple
    > > >
    > > > declare with namespace, like this
    > > > Protected WithEvents mySimple As mySimpleNS.Simple
    > > >
    > > > I think that is the issue
    > > >
    > > > --
    > > > Saravana
    > > > http://dotnetjunkies.com/WebLog/saravana/
    > > > www.ExtremeExperts.com
    > > >
    > > >
    > > > "Mat" <> wrote in message
    > > > news:...
    > > > > Hi,
    > > > >
    > > > > I am having a bit of a problem trying to access / set properties of a
    > > > > usercontrol from the parent codebehind.
    > > > >
    > > > > This is what I have so far..
    > > > >
    > > > > simple.aspx
    > > > > <%@ Page Inherits="CodeBehindSimple" src="simple.vb" %>
    > > > > <%@ Register TagPrefix="CC" TagName="Simple" Src="ucSimple.ascx"%>
    > > > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
    > > > > "http://www.w3.org/TR/REC-html40/strict.dtd">
    > > > > <html>
    > > > > <head>
    > > > > <meta http-equiv="Content-Type" content="text/html;
    > > > > charset=iso-8859-1">
    > > > > <title></title>
    > > > > </head>
    > > > > <body>
    > > > >
    > > > > <form runat="server">
    > > > >
    > > > > <CC:Simple id="mySimple" myParam="Hello from aspx" runat="server" />
    > > > >
    > > > > </form>
    > > > >
    > > > > </body>
    > > > > </html>
    > > > >
    > > > > simple.vb
    > > > > Imports System
    > > > > Imports System.Web.UI
    > > > > Imports System.Web.UI.WebControls
    > > > > Imports System.Web.UI.HtmlControls
    > > > >
    > > > > Public Class CodeBehindSimple
    > > > > Inherits Page
    > > > >
    > > > > Protected WithEvents mySimple As Simple
    > > > >
    > > > > sub Page_Load
    > > > > mySimple.myParam = "Hello from codebehind"
    > > > > end sub
    > > > > End Class
    > > > >
    > > > > ucSimple.ascx
    > > > > <%@ Control Language="VB" Inherits="mySimpleNS.Simple"
    > > > > src="./ucSimple.vb"%>
    > > > >
    > > > >
    > > > > <asp:Label id="lbl_Simple" runat="server" />[/code]
    > > > >
    > > > > ucSimple.vb
    > > > >
    > > > > Imports System
    > > > > Imports System.Web.UI
    > > > > Imports System.Web.UI.WebControls
    > > > > Imports System.Web.UI.HtmlControls
    > > > >
    > > > > Namespace mySimpleNS
    > > > >
    > > > > Public Class Simple
    > > > > Inherits UserControl
    > > > >
    > > > > Protected WithEvents lbl_Simple as Label
    > > > >
    > > > > public property myParam as string
    > > > > get
    > > > > return lbl_Simple.text
    > > > > end get
    > > > > set
    > > > > lbl_Simple.text = value
    > > > > end set
    > > > > end property
    > > > >
    > > > > End Class
    > > > >
    > > > > End Namespace
    > > > >
    > > > > What should happen is that the parent codebehind (simple.vb) should
    > > > > update the usercontrol CC:Simple "myParam" with "Hello from
    > > > > codebehind". This dont happen, I get an error:
    > > > >
    > > > > BC30002: Type 'Simple' is not defined.
    > > > >
    > > > > If I comment out (in simple.vb)
    > > > > 'Protected WithEvents mySimple As Simple
    > > > >
    > > > > 'sub Page_Load
    > > > > ' mySimple.myParam = "Hello from codebehind"
    > > > > 'end sub
    > > > >
    > > > > I get the text set in the parent (simple.aspx) output.
    > > > >
    > > > > Anyone got any ideas? BTW I am not using VS.Net.
    > > > >
    > > > > Cheers.
     
    Mat, Oct 29, 2004
    #5
    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. Phl
    Replies:
    2
    Views:
    543
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=
    Nov 18, 2004
  2. N. Demos
    Replies:
    0
    Views:
    458
    N. Demos
    Jun 19, 2005
  3. protic
    Replies:
    0
    Views:
    362
    protic
    Oct 15, 2008
  4. jdn
    Replies:
    3
    Views:
    202
  5. Support

    accessing a parent function from a usercontrol...

    Support, Mar 29, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    105
    Support
    Mar 29, 2005
Loading...

Share This Page