PDA

View Full Version : [CLOSED] [2.2] DirectEvents "An error has occurred because a control..."



michaeld
Jul 30, 2013, 4:09 AM
"An error has occurred because a control with id 'ctl00$cp$ctl07' could not be located or a different control is assigned to the same ID after postback."


I've been seeing errors like this only recently but only in directevent postback on a page where a lot of dynamic controls are created. The problem is, the shear number of controls and complexity is making it virtually impossible for me to produce a reproducible test sample with the same situation.

I need clues on what to look for. I verified that the issue is not that the loading of missing usercontrols.

The first time I had this problem, I had rewrite menu control loader that moved some controls from one loaded user control and move it to another control elsewhere. That problem went away after I updated the loader to move the control from a user control before adding the user control to the items of a usercontrolloader.

This time, I'm trying to load a UserControl with a ext:Window in its contents from a UserControlLoader that is being added into a Panels Bin.Add().

I cannot trap on the Page_Load of the UserControl which is why I'm getting the error above. It's not executing the pageload event even though the user control is loaded.

Thoughts?

Daniil
Jul 30, 2013, 4:57 AM
Hi @michaeld,

It worked for me as well. Do you mind we close the thread or you are working on another test case?

michaeld
Jul 30, 2013, 5:14 AM
I've revised and added...

michaeld
Jul 30, 2013, 5:51 AM
I have 2 versions of essentially the same code below. One traps at the breakpoint I set in Page_Load of the User control referenced by the string taskctl.

This one does not trap at Page_Load on postback or initial load...


var ctl = new UserControlLoader( new UserControlLoader.Config() { Path = taskctl } );
ctl.UserControlID = "TaskUC" + i.ToString();
ProfP.Bin.Add( ctl );


This version traps at Page_Load on both postback and initial load...


var uc = Page.LoadControl( taskctl ) as UserControl;
var ctl = new UserControlLoader();
ctl.Items.Add( uc );
ctl.UserControlID = "TaskUC" + i.ToString();
ProfP.Bin.Add( ctl );


Both versions upon loading the Bin.Add user control will produce the error msg I indicated at the top of this thread.

If I remark out this section and postback, the direct event runs normally without any errors.

michaeld
Jul 30, 2013, 7:04 AM
I think I may have some clues to what is causing the original failure message behavior. The issue is that the postback requires that every control that was rendered before be in the exact same position as it was when it was rendered the first time.

For performance reasons I was skipping some of the reorganization steps on the postback. When I removed this step, the problem went away. This was throwing off UserControlLoader ids or postback viewstate binding on postback or something.

I cannot explain why the code differences above had any impact on behavior but I suspect there's a clue in there. I'm guessing how it renders or manages ids. Typically, I don't believe this would be an issue if I used a classic Page.LoadControl and skipped the reorder because all the ids were present, just in different locations. I can't confirm but I'm pretty sure I didn't have these problems in the 1.0 version.

Anyway, you can close this item unless you want to discuss or evaluate further why this might happen in UserControlLoader.

Daniil
Jul 30, 2013, 10:25 AM
Typically, I don't believe this would be an issue if I used a classic Page.LoadControl and skipped the reorder because all the ids were present, just in different locations.

I guess the same should be reproducible with a pure LoadControl without a UserControlLoader. We don't do anything special in a UserControlLoader. However, anything is possible. We would be happy to investigate a test case if you can provide.