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!
 
A

Alex Meleta

Hi,

The databinding syntax <%# ... %> certainly is applied after DataBind().

E.g.
Page...
protected void Page_Load(object sender, EventArgs e)
{
ctrl1.MyParent; // nothing
this.DataBind();
ctrl1.MyParent; // <this> there
}

Regards, Alex
[TechBlog] http://devkids.blogspot.com



m> ="<%# this %>"
m>
 

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