views:

312

answers:

1

I am in the middle of an ASP.NET project where I am using the CSLA framework and the AJAX ModalPopupExtender control. I have used CSLA and the ModalPopupExtender in different projects before, but this is the first time I am using them together.

The way I want it to work is for the user to push a button, which will create an instance of an object and show the modal popup. The popup has controls bound to a CslaDataSource, based on the object that was just created.

Instead the way it actually works is it is loading the controls on the ModalPopup even when the popup is still hidden, e.g. during the initial page load. This generates an error, since the object to which the controls are binding does not exist yet, so it is not able to render the controls and the corresponding Javascript on the aspx page correctly. The error is: "Microsoft JScript runtime error: Sys.ArgumentNullException: Value cannot be null. Parameter name: element"

My current workaround is to create a dummy object upfront, just so there is something the controls on the popup can bind to initially. I then replace that object when the user pushes the button. I am wondering if there is a simpler way with less overhead that I may be missing.

A: 

Even though the controls are hidden, they are still created and they still go through the web forms page lifecycle. The ModalPopup just displays the already bound and rendered controls.

I would suggest using a javascript ajax method (create an XmlHttp object -- this is very easy to do with jquery). Your controls will be rendered and go through the page lifecycle at that time. Your binding will occur with the CslaDataSource OnSelectObject method.

Jamie Wright