UserControl reference problem

M

mAbZ

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) but
value in MyParent property's setter is null.
So the reference is not beaing passed.

What am I missing??
I could set this value in OnDataBind but don't know how to get it there from
the aspx page.

I've been reading a number of tutorials on DataBinding, but not found any
solution to this.
Please, help!
 
B

bruce barker

the Page class does not support databind, so your control has to be
contained in one that does, Repeater, GridView, FormView, etc. then in
the codebehind, you need to call DataBind() on the parent control.

a better approach then using a databinding expression when you are not
using databind, would be to re-engineer MyParent to MyParentID. then you
would just set the parent name in the aspx. in the control code recurse
thru control.Parent.FindControl(parentName) to get the actual control.
if you just want the Page (this), every control has a Page property that
is the Page.

-- bruce (sqlwork.com)
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top