Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Accessing a usercontrol from parent codebehind

Reply
Thread Tools

Accessing a usercontrol from parent codebehind

 
 
Mat
Guest
Posts: n/a
 
      10-28-2004
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.
 
Reply With Quote
 
 
 
 
Saravana
Guest
Posts: n/a
 
      10-28-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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.



 
Reply With Quote
 
 
 
 
Mat
Guest
Posts: n/a
 
      10-28-2004
Nope, didnt fix it. I now get

BC30002: Type 'mySimpleNS.Simple' is not defined

Cheers,
Mat.

"Saravana" <(E-Mail Removed)> wrote in message news:<rA3gd.1764$(E-Mail Removed)>...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > 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.

 
Reply With Quote
 
Saravana
Guest
Posts: n/a
 
      10-29-2004
Add Reference to ucsimple.dll when you are compiling your codebehind.

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


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

news:<rA3gd.1764$(E-Mail Removed)>...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) om...
> > > 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.



 
Reply With Quote
 
Mat
Guest
Posts: n/a
 
      10-29-2004
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" <(E-Mail Removed)> wrote in message news:<fIigd.1874$(E-Mail Removed)>...
> Add Reference to ucsimple.dll when you are compiling your codebehind.
>
> --
> Saravana
> http://dotnetjunkies.com/WebLog/saravana/
> www.ExtremeExperts.com
>
>
> "Mat" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > Nope, didnt fix it. I now get
> >
> > BC30002: Type 'mySimpleNS.Simple' is not defined
> >
> > Cheers,
> > Mat.
> >
> > "Saravana" <(E-Mail Removed)> wrote in message

> news:<rA3gd.1764$(E-Mail Removed)>...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed) om...
> > > > 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Accessing vb of usercontrol within usercontrol protic ASP .Net 0 10-15-2008 11:26 AM
accessing a parent function from a usercontrol... Support ASP .Net Web Controls 0 03-29-2005 05:56 PM
accessing usercontrol from another usercontrol Phl ASP .Net 2 11-18-2004 07:33 PM
Problem accessing UserControl properties from ASP.NET Web Form CodeBehind jdn ASP .Net Web Controls 3 09-17-2003 11:39 PM



Advertisments