Possible bug with LLBLGenProDataSource2 usage

Posts   
 
    
Ian G
User
Posts: 2
Joined: 22-May-2007
# Posted on: 20-Jun-2007 04:10:42   

Hi,

Using Adapter, .net 2.0.

Maybe this is a problem with the usage scenario but if anyone is able to shed any light on this then I would be grateful. I have basically implemented a custom master page (I did this prior to .net and still use the code. It also allows for the actual master page template to be themed - something I don't believe the .net implementation of master pages does?). Anyway the code basically works like this; OnInit is overridden in the Skin class, the Skin class is a server control with a template parameter that can be set in the tag. The LoadControl method loads the control at runtime and adds each of the controls in the load control (user desired template) into its own collection. This basically loads the desired template into the current control (the catch and initialising of a string to the message was only added to diagnose the problem, I would never normally catch and swallow base type Exception simple_smile )

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            Control control = LoadControl();

            while (control.Controls.Count != 0)
            {
                Control controlToAdd = control.Controls[0];
                try
                {
                    control.Controls.Remove(controlToAdd);
                }
                catch (Exception ex)
                {
                    string s = ex.Message;
                }
                Controls.Add(controlToAdd);
            }
        }

The remove also didn’t used to be in there but I added it to diagnose the problem, the code just used to add the control. Anyway to cut a long story short when it comes to adding the LLBLGenProDataSource2 control from the loaded control into the instantiated control - Controls.Add(controlToAdd); an exception is thrown. Here is the stack trace

at System.Web.UI.WebControls.DataBoundControlHelper.FindControl(Control control, String controlID) at System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) at System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) at System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) at System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceViewBase.GetParameterValues(ParameterCollection parameters, Dictionary`2 destination) at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceViewBase.CreateStateDataObject() at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView2.CreateStateDataObject() at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceBase.CreateStateDataObject() at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceBase.OnDataSourceUnload(Object sender, EventArgs e) at System.Web.UI.Control.OnUnload(EventArgs e) at System.Web.UI.Control.UnloadRecursive(Boolean dispose) at System.Web.UI.Control.RemovedControl(Control control) at System.Web.UI.ControlCollection.RemoveAt(Int32 index) at System.Web.UI.ControlCollection.Remove(Control value) at ScratchTracks.UI.Web.Controls.Skin.OnInit(EventArgs e) in C:\temp\ScratchTracks\UIWeb\Controls\Skin.cs:line 60

The exception message is: The LLBLGenProDataSource2 control 'llblgenDS' does not have a naming container. Ensure that the control is added to the page before calling DataBind.

This has been frustrating me a lot and I have tried to get to the bottom of it. The control it is being added to derives from INamingContainer as does the control it first exists on as a child control (the NamingContainer property can be visibly seen in both cases).

I checked up the call stack and looked at some of the LLBLGen source and found the OnDataSourceUnload method in LLBLGenProDataSourceBase. This does a switch on the cache type and acts if the cache type is session. I therefore changed to cache type of the data source control to viewstate and I didn't have this problem anymore. I would rather use the session and would rather not use the work around I have in place at the moment (I would change the catch to catch System.Web.HttpException and rethrow if it wasn’t caused by a data source control).

Any help would be appreciated, thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Jun-2007 15:26:44   

mmm... are you sure the onInit() event is the best place to load those controls? Does this exception occur on a postback?

Would you check the following article (and check the comments down-under): http://www.csharper.net/blog/adding_controls_dynamically_to_a_page_in_asp_net.aspx

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39912
Joined: 17-Aug-2003
# Posted on: 20-Jun-2007 22:21:14   

I also think that the init event handler isn't the one to perform any actions on datasourcecontrols.

Frans Bouma | Lead developer LLBLGen Pro