file-uploadasynchronousdotnetnukesetting

Using FileUpload in DNN Setting.ascx possible?


first time asking a question here.

I'm making a DNN module and in the Setting.ascx I'm trying to add any form of FileUpload in there. I'm successful at adding ASP's FileUpload as well as Telerik's RadUpload, but when I click a button I added to save and examine the uploaded the file it's empty and no longer holding any data. I thought I was coding it wrong at first, but after adding it into the View.ascx instead it works perfectly. Of course that's not where I want it to be.

I believe the problem might be how the Setting.ascx works in DNN. I believe it's using a form of AJAX to display it so that might be interfering. Hard to say though. While I'm at it can anyone confirm that Setting.ascx is using AJAX and that button clicks cause asynchronous postbacks? Thanks.


Solution

  • You're right with your thought that the form uses AJAX (formerly via UpdatePanel, now via RadAjaxPanel in DNN 6.x), and that's what's interfering with the upload. In most scenarios, you'd just switch to a regular postback by calling ScriptManager.RegisterPostBackControl, but in the settings case, you don't have a direct reference to the LinkButton that saves the settings.

    You'll probably need to add your own button to the form to do the upload after the user has selected the file. DNN's own UrlControl uses a system like that, where there's an Upload button next to the Browse button. DNN also has a newer DnnFilePicker control, which might also encapsulate what you want. You'll just need to add an @ Register directive to use those. For example:

    <%@ Reference tagPrefix="dnn" tagName="UrlControl" Src="~/controls/URLControl.ascx" %>
    <%@ Reference tagPrefix="dnn" Assembly="DotNetNuke.Web" Namespace="DotNetNuke.Web.UI.WebControls" %>
    
    <dnn:UrlControl runat="server" ID="FileUpload" 
                    ShowLog="false"
                    ShowNewWindow="false"
                    ShowTrack="false"
                    ShowImages="false"
                    ShowNone="false"
                    ShowTabs="false"
                    ShowUrls="false"
                    ShowUsers="false"
                    ShowFiles="false"
                    ShowUpLoad="true" />
    
    <dnn:DnnFilePicker runat="server" ID="FilePicker"
                       FileFilter="jpg,png,gif" />