Search code examples
asp.netcode-behindascx

Control within ascx is null when ascx is added from codebehind


I am having difficulties how to construct my question, but if I have to put it simply the situation is that I have categories of products. I have an aspx with a repeater on the left that lists the categories. And I want the products to be listed on the right. Category number is variable so I made an ascx with a DataList in it. When I try to do foreach category, ascx = new ascx(); then the DataList within this ascx control is null.

ps: what I want to do is to preload all the products (thre is not much) and hide the divs and fadein fadeout them using jQuery when a category div is clicked.

rightnow it is using jQuery.load(); and I don't like how the images load, cuz they download from top to bottom. Progressive gifs alsdo not an option. site demo is here http://techlipse.net/test/ledart

Thanks a lot in advance...


Solution

  • You need to use LoadControl(pathtoaspx) instead.

    var ctrl = LoadControl("details.ascx") as MyControlClass;
    // you can access public properties after this
    ctrl.Data = user; 
    placeholder.Add(ctrl);