4

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.

Mitchell
  • 253
  • 1
  • 5
  • 16

3 Answers3

3

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" />
bdukes
  • 152,002
  • 23
  • 148
  • 175
  • I get the "The Reference directive must have a VirtualPath attribute, and no other attributes." When using that as a reference. Shouldn't I be using Register with that? Oh an does UrlControl or DnnFilePicker have any OnClick events or something? – Mitchell Mar 21 '12 at 13:08
  • I used Register instead and got things working, but using the UrlControl causes Uploaded % ( ) Total Uploaded files: % () Total files: Uploading file: Elapsed time: Estimated time: Speed: --> to show up. Is that supposed to happen? – Mitchell Mar 21 '12 at 13:51
  • For some reason now, the designer is sayind DnnFilePicker does not exist. I also can't seem it find DnnFilePiecker under DotNetNuke.Web.UI.WebControls.DnnFilePicker – Mitchell Mar 21 '12 at 14:36
  • I got the thing working, but it doesn't quite have the functionality I'm looking for. Was wanting to keep track of what things users upload to that specific ID of that module on that page etc. If there's some on event I could maybe catch what's uploaded and save it. Alternatively I could have users select from the list of loaded items and save that as one of the specific files. – Mitchell Mar 21 '12 at 15:52
  • If you're wanting to manually keep track of files, then those controls won't help (since they give full access to the DNN file system). In that case, you'll want to manually implement the pattern of ` ` – bdukes Mar 21 '12 at 19:07
  • Manually implement it? Problem is asp:FileUpload won't work properly in the Setting.ascx. I am trying the FileUpload, but can't figure out how to get access to the currently selected file in the drop down list. – Mitchell Mar 21 '12 at 19:30
  • 2
    Call `DotNetNuke.Framework.AJAX.RegisterPostBackControl`, passing in the `UploadButton`, and that will let the file upload work, so that you can access the file on postback. – bdukes Mar 22 '12 at 12:26
0

Man, just don't put a updatepanel outside your ascx control If you need to use updatepanel, put it inside the ascx. That will resolve your problem!

Marquinho Peli
  • 4,795
  • 4
  • 24
  • 22
0

I was able to solve this problem by doing the following:

  • Create my own submit button as opposed to relying on the "Save" button built into the page
  • Adding the following to my LoadSettings() method:

    ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(cmdUpload);

Where cmdUpload is the ID of my submit button.

You will need to add a reference to System.Web and System.Web.Extensions for this to compile.

Rick
  • 1,863
  • 2
  • 19
  • 46