Using FileUploader in a Dynamically loaded UserControl

Nov 26, 2008 at 12:34 AM
I've tried to use the FileUploader from within a UserControl that I dynamically load within my page's OnInit but all I see is a url link "Please install Adobe Flash Player" instead of the normal UI features.  If I place another FileUploader on the (static) page itself I see the normal UI for this control.  Why does the control not display correctly in a dynamically loaded UserControl?

Nov 26, 2008 at 2:18 AM
Can you make a test sample of the problem and zip it and attach as an issue?
Nov 26, 2008 at 3:35 AM
I will attempt to shortly.  I'm thinking though that it is similar to the AjaxToolkit Tab issue I've seen in other discussions so attempting to execute the _initialize javascript function during the usercontol's init event.

Will keep you posted soon.
Nov 26, 2008 at 5:05 AM
I've added a demonstration of the problem here
Nov 26, 2008 at 7:09 AM
You cannot use a JavaScript inside an update panel that IS NOT initially loaded on the page. This is a limitation of the Update Panel and not a limitation of the FileUploader. If you still want to follow this model and load reach content with Ajax calls you have to take care of the JavaScript initializations. One approach I can recommend is to place FileUploaders on the page inside an invisible div then use Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InitFunc) where InitFunc will take care to initialize and move the uploader to where you want it to be.
Nov 26, 2008 at 7:11 AM
To make myself more clear - place a <script>alert(1)</script> statement inside your controls and you will see it will never be fired.
Nov 26, 2008 at 8:45 AM
So how come I have no problems with dynamically loaded user controls in my application that make extensive use of ajaxtoolkit extender controls?  The extenders use javascript that executes perfectly fine.
Nov 26, 2008 at 3:20 PM
What flajaxian is saying is that you can't use *client* javascript. The toolkit extenders are written specially to render their javascript to the browser at the appropriate point - their javascript works fine because that's exactly what they're meant to do.
Nov 26, 2008 at 3:50 PM
ajaxtoolkit has a dependency on Ajax.Asp.Net framework, so you can't use it without it. Flajaxian does not have it.

Why do you need to load different FileUploaders? Load one and then just reposition it.

Nov 26, 2008 at 9:59 PM
If that is the only solution then that is what I shall have to do, or look for another control that supports the updatepanel and scriptmanager.  The reason I don't like it is my dynamic user control loading framework was put in place to "reduce" the controls that were loaded at any one time, both from a server side but also a client side (javascript).

I don't "need" different File Uploaders so sorry for misleading anyone there.  The FileUploader control would be positioned (visually) inside of an ajaxtoolkit modal popup in a user control that is nested deep within a page hierarchy of other user controls that are themselves loaded dynamically.  The modal popup can be repositioned from a client side, which incidentally happens when the popup first appears.  I'd have to capture this move at the client and reposition the fileuploader which I'm not sure how to do.  If the FileUploader were within the hierarchy of the dynamic user control then repositioning is automatic.

The easiest solution of course is to make this "Add Attachment" user control just a generic control that is not loaded dynamically but always available.  This goes against our policy of loading user controls that aren't used which would be the case for 99% of the application's normal use.
Nov 26, 2008 at 11:33 PM
What I would recommend then would be something like that:

<fjx:FileUploader ID="FileUploader2" JsFunc_Init="InitUploader" JsFunc_Dispose="DisposeUploader" runat="server">
<script type="text/javascript">
    function PageIsLoaded(){
        // here reposition the uploader
    function BeforeReload(){
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded( PageIsLoaded );
    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest( BeforeReload );
Nov 27, 2008 at 2:40 AM
Thanks flajaxian, I'll give that a shot.