How to get reference to parent class from user control?

B

Brent

This is one of those issues where I'm wondering if i'm going about this the
right way...

In a user control, I need a reference to an instance of the parent page's
class. How do you get it?

--------

Why do i need it? I have a page, Page1, with 2 user controls: UC1 and UC2.

The 1st user control has a dropdownlist (ddl). The 2nd control contains the
javascript (js) biz logic that calls a js function (in a .js file). The
function in the js file has to know the clientID of the ddl so that it can
create a reference to it. To get the ddl clientID all the way to the js
function, Page1 has a DDLUsersClientID property that UC1 sets and UC2 reads.
The problem is that i don't know how to get a reference to Page1 from UC1.

Page1
------------------
Public Class Page1
Inherits System.Web.UI.Page
Public Property DDLUsersClientID() As String
Get
Return mstrDDLUsersClientID
End Get
Set(ByVal ClientIDIN As String)
mstrDDLUsersClientID = ClientIDIN
End Set
End Property


UC1 on Page1
-------------------
Public Class SubscribeShowSolutions
Inherits System.Web.UI.UserControl
Public cPage1 As Page1
Protected ddlUsers As DropDownList

cPage1 = Parent. ? ? ?
cPage1.DDLUsersClientID = ddlUsers.ClientID 'Set ddluserclientid to parent
page so that UC2 can read it and pass it to js fct.

Thanks for any advice!

Brent
BugMonitor.com
 
P

Peter Rilling

Create a property that can be set to the Page instance in your usercontrol.
Assign this when the page loads.
 
B

Brent

Ok.

Thanks!

Brent
BugMonitor.com

Peter Rilling said:
Create a property that can be set to the Page instance in your usercontrol.
Assign this when the page loads.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top