473,583 Members | 3,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing a usercontrol from parent codebehind

Mat
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="CodeB ehindSimple" src="simple.vb" %>
<%@ Register TagPrefix="CC" TagName="Simple " Src="ucSimple.a scx"%>
<!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.W ebControls
Imports System.Web.UI.H tmlControls

Public Class CodeBehindSimpl e
Inherits Page

Protected WithEvents mySimple As Simple

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

ucSimple.ascx
<%@ Control Language="VB" Inherits="mySim pleNS.Simple"
src="./ucSimple.vb"%>
<asp:Label id="lbl_Simple " runat="server" />[/code]

ucSimple.vb

Imports System
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H tmlControls

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.myPara m = "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.
Nov 18 '05 #1
4 1873
Instead of declaring
Protected WithEvents mySimple As Simple

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

I think that is the issue

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Mat" <ma*@u2orange.c o.uk> wrote in message
news:a7******** *************** ***@posting.goo gle.com...
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="CodeB ehindSimple" src="simple.vb" %>
<%@ Register TagPrefix="CC" TagName="Simple " Src="ucSimple.a scx"%>
<!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.W ebControls
Imports System.Web.UI.H tmlControls

Public Class CodeBehindSimpl e
Inherits Page

Protected WithEvents mySimple As Simple

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

ucSimple.ascx
<%@ Control Language="VB" Inherits="mySim pleNS.Simple"
src="./ucSimple.vb"%>
<asp:Label id="lbl_Simple " runat="server" />[/code]

ucSimple.vb

Imports System
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H tmlControls

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.myPara m = "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.

Nov 18 '05 #2
Mat
Nope, didnt fix it. I now get

BC30002: Type 'mySimpleNS.Sim ple' is not defined

Cheers,
Mat.

"Saravana" <sa******@sct.c o.in> wrote in message news:<rA******* *********@news. cpqcorp.net>...
Instead of declaring
Protected WithEvents mySimple As Simple

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

I think that is the issue

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Mat" <ma*@u2orange.c o.uk> wrote in message
news:a7******** *************** ***@posting.goo gle.com...
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="CodeB ehindSimple" src="simple.vb" %>
<%@ Register TagPrefix="CC" TagName="Simple " Src="ucSimple.a scx"%>
<!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.W ebControls
Imports System.Web.UI.H tmlControls

Public Class CodeBehindSimpl e
Inherits Page

Protected WithEvents mySimple As Simple

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

ucSimple.ascx
<%@ Control Language="VB" Inherits="mySim pleNS.Simple"
src="./ucSimple.vb"%>
<asp:Label id="lbl_Simple " runat="server" />[/code]

ucSimple.vb

Imports System
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H tmlControls

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.myPara m = "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.

Nov 18 '05 #3
Add Reference to ucsimple.dll when you are compiling your codebehind.

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Mat" <ma*@u2orange.c o.uk> wrote in message
news:a7******** *************** ***@posting.goo gle.com...
Nope, didnt fix it. I now get

BC30002: Type 'mySimpleNS.Sim ple' is not defined

Cheers,
Mat.

"Saravana" <sa******@sct.c o.in> wrote in message

news:<rA******* *********@news. cpqcorp.net>...
Instead of declaring
Protected WithEvents mySimple As Simple

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

I think that is the issue

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Mat" <ma*@u2orange.c o.uk> wrote in message
news:a7******** *************** ***@posting.goo gle.com...
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="CodeB ehindSimple" src="simple.vb" %>
<%@ Register TagPrefix="CC" TagName="Simple " Src="ucSimple.a scx"%>
<!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.W ebControls
Imports System.Web.UI.H tmlControls

Public Class CodeBehindSimpl e
Inherits Page

Protected WithEvents mySimple As Simple

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

ucSimple.ascx
<%@ Control Language="VB" Inherits="mySim pleNS.Simple"
src="./ucSimple.vb"%>
<asp:Label id="lbl_Simple " runat="server" />[/code]

ucSimple.vb

Imports System
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H tmlControls

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.myPara m = "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.

Nov 18 '05 #4
Mat
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" <sa******@sct.c o.in> wrote in message news:<fI******* *********@news. cpqcorp.net>...
Add Reference to ucsimple.dll when you are compiling your codebehind.

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Mat" <ma*@u2orange.c o.uk> wrote in message
news:a7******** *************** ***@posting.goo gle.com...
Nope, didnt fix it. I now get

BC30002: Type 'mySimpleNS.Sim ple' is not defined

Cheers,
Mat.

"Saravana" <sa******@sct.c o.in> wrote in message

news:<rA******* *********@news. cpqcorp.net>...
Instead of declaring
Protected WithEvents mySimple As Simple

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

I think that is the issue

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Mat" <ma*@u2orange.c o.uk> wrote in message
news:a7******** *************** ***@posting.goo gle.com...
> 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="CodeB ehindSimple" src="simple.vb" %>
> <%@ Register TagPrefix="CC" TagName="Simple " Src="ucSimple.a scx"%>
> <!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.W ebControls
> Imports System.Web.UI.H tmlControls
>
> Public Class CodeBehindSimpl e
> Inherits Page
>
> Protected WithEvents mySimple As Simple
>
> sub Page_Load
> mySimple.myPara m = "Hello from codebehind"
> end sub
> End Class
>
> ucSimple.ascx
> <%@ Control Language="VB" Inherits="mySim pleNS.Simple"
> src="./ucSimple.vb"%>
>
>
> <asp:Label id="lbl_Simple " runat="server" />[/code]
>
> ucSimple.vb
>
> Imports System
> Imports System.Web.UI
> Imports System.Web.UI.W ebControls
> Imports System.Web.UI.H tmlControls
>
> 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.myPara m = "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.

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
999
by: kevin | last post by:
I want to create basic usercontrol code libraries. Is the following possible? If so, how? As a front-end developer being exposed to the concept of usercontrols, I thought (asked the question), with .net it must be possible to have template files that contain similar front-end static or dynamic code from which code be called, much in the...
3
1681
by: Iain | last post by:
Hi I have page (testCal.aspx) that contains a usercontrol (custCalendar.ascx) - see below signature for code. The UC contains a linkbutton which which when clicked, posts back and displays a calendar. When a value in the calendar is selected it posts back and then updates a public property (CurrentDate) on the UC. Note that 2 postbacks...
6
1928
by: Pete Davis | last post by:
I'm fairly weak with ASP.NET. What I'm trying to do is pass an attribute to a UserControl. The attribute is a value from the CodeBehind for the page. So in my .aspx I have the following: <cm:Comments runat="server" ID="Comments1" CommentType="News" ItemID="<%= NewsItemID %>" /> NewsItemID is a property in the CodeBehind for the page.
0
1525
by: N. Demos | last post by:
Hello, I have a custom usercontrol, of which I have two instances of in my aspx page. Both the usercontrol and page have codebehind. In the page codebehind, I want a member variable for each usercontrol. My problem is that I keep getting a compiler error on the usercontrol variables in my page codebehind (BC30002: Type 'CityGeoPosSelectClass'...
9
14432
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem is that the webcontrols get created on the OnLoad event of the usercontrol and the event handlers are assigned at the same...
10
2409
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's my question. Once the UserControl is dropped onto the container page, how can I perform some action on the codebehind of the container page from...
9
2637
by: J055 | last post by:
Hi I have a standard asp page which uses a MasterPage. The MasterPage contains a User control. How can I access a public method in the User control from my WebForm page? I can't move the method to another location because it populates a Textbox in the user control page. Thanks Andrew
14
3187
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I have created a UserControl ("MyUC"). I've put a bunch of instances of that control on a Page ("Defaul.aspx"). The control works fine. Now, I want to be able to use "FindControl()" from within my Default.aspx as follows: MyUC C = (MyUC)this.FindControl("SomeID"); When I try to run this, I get error: "The type or namespace name...
1
1589
by: mAbZ | last post by:
I neeed to instantiate an UserControl in an aspx page like this: <MyNamespace:MyControl ID="ctrl1" runat="server" MyParent="<%# this %>" /> where "this" is the current aspx page and should be assigned to property Parent contained in MyControl class. Above code is contained in a PlaceHolder. When debuging, "this" is not null (obviously)...
0
7821
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7929
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8190
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5697
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5370
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3814
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1424
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1152
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.