Accessing a usercontrol from parent codebehind

This is a discussion on "Accessing a usercontrol from parent codebehind" within the ASP.NET Forum section. This forum, and the thread "Accessing a usercontrol from parent codebehind are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > ASP.NET Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 28th, 2004, 08:28
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Accessing a usercontrol from parent codebehind

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
Code: Select all
<%@ 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
Code: Select all
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
Code: Select all
<%@ Control Language="VB" Inherits="mySimpleNS.Simple" src="./ucSimple.vb"%>


<asp:Label id="lbl_Simple" runat="server" />
ucSimple.vb
Code: Select all
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:
Code: Select all
BC30002: Type 'Simple' is not defined.
If I comment out (in simple.vb)
Code: Select all
'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.

  #2 (permalink)  
Old Oct 28th, 2004, 11:16
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
Cant find the exact answer to this on google, but making it Public or using a Base or something!? seems to be the way forward:

http://www.google.co.uk/search?hl=en...behind&spell=1
  #3 (permalink)  
Old Oct 28th, 2004, 13:52
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Both classes are public and both are inheriting correctly so i am a little confused...
Closed Thread

Tags
accessing, usercontrol, parent, codebehind

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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
guidance in accessing variables balaakrs Classic ASP 3 Nov 2nd, 2007 08:06
Accessing a movie clip ClrWtrDsgnr Flash & Multimedia Forum 1 Sep 10th, 2007 13:23
problem accessing page number9 Starting Out 4 May 25th, 2007 05:30
Accessing Data OmiE Starting Out 1 May 9th, 2007 20:22
parent daughter maxelcat Web Page Design 3 Aug 14th, 2006 23:34


All times are GMT. The time now is 22:48.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43