Using FileUpload in DNN Setting.ascx possible? - file-upload

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.

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" />

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!

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.

Related

DNN - What control to use for images in custom module settings?

I am creating modules using the template created by Chris Hammond (TYVM Chris).
My modules have a few things that can be edited by the user in the settings area, one of them being an image.
I can use a TextBox and have the user type the root relative path to the image, but it is a little clunky because the user has to upload the image in the file management area of the website, get the path, then add it to the module settings. It would be a lot smoother if I could have a Image selector that would tie into the DNN files and allow the user to select an image that has been previously uploaded to DNN or add their own.
How would one accomplish this?
I suggest you to use the FilePickerUploader control of DNN.
You could see what it looks like in the Portal Settings (in Admin menu). It's used for the selection of the logo file, background image and favicon.
For example, it could be use like this:
<%# Register TagPrefix="dnn" TagName="FilePickerUploader" Src="~/controls/filepickeruploader.ascx" %>
<dnn:FilePickerUploader ID="ctlFavIcon" runat="server" Required="True" FileFilter="ico" />
Required and FileFilter attributes are optionnal and I think it provides other options.
Just use a DNNEditor webcontrol
<%# Register TagPrefix="dnn" Assembly="DotNetNuke.Web" Namespace="DotNetNuke.Web.UI.WebControls" %>
<dnn:DnnEditor ToolsFile="xmfile.xml"/>
Via this control you can use the default image selector. In first place you will see a lot of selectors in the toolbar, but you can change this via a xml file and add that xml file to the property ToolsFile
Just let me know if you need more help.

PrestaShop - Reload CMS page with additional parameters

Situation: I needed to add form with POST method to CMS page. I created custom hook and a module displaying the form successfully. Then I need to react to user input errors eg. when user doesn't enter email address I need to detect it, display the whole page again together with the form and with "errors" in user input clearly stated.
Problem: The problem is to display the WHOLE page again with connected information (eg. about errors etc.). In the module PHP file when I add this kind of code,
return $this->display(__FILE__, 'modulename.tpl');
it (naturally) displays ONLY the form, not the whole CMS page with the form.
In case of this code,
Tools::redirectLink('cms.php?id_cms=7');
I can't get to transfer any information by GET neither POST method.
$_POST['test'] = 1;
Tools::redirectLink('cms.php?id_cms=7&test');
I tried to assign to smarty variables too
$smarty->assign('test', '1');
(I need to use it in .tpl file where the form itself is created) but no way to get it work.
{if isset($test)}...,
{if isset($smarty.post.test)}...,
{if isset($_POST['test'])}... {* neither of these conditionals end up as true *}
Even assigning a GET parameter to url has no impact, because there is link rewriting to some kind of friendly url I guess, no matter I included other argument or not. ([SHOPNAME]/cms.php?id_cms=7&test -> [SHOPNAME]/content/7-cmspage-name)
My question is: is there a way to "redirect" or "reload" current page (or possibly any page generally) in prestashop together with my own data included?
I kind of explained the whole case so I'm open to hear a better overall solution than my (maybe I'm thinking about the case in a wrong way at all). This would be other possible answer.
The simplest method would be to use javascript to validate the form - you can use jQuery to highlight the fields that are in error; providing visual feedback on how the submission failed. In effect you don't allow the user to submit the form (and thus leave the page) until you're happy that the action will succeed. I assume that you will then redirect to another page once a successful submission has been received.
There's lots of articles and how-tos available for using javascript, and indeed jQuery for form validation. If you want to keep the site lean and mean, then you can provide an override for the CMS controller and only enqueue the script for the specific page(s) you want to use form validation on.
If the validation is complex, then you might be best using AJAX and just reloading the form section of your page via a call to your module. Hooks aren't great for this kind of thing, so you might want to consider using an alternative mnethod to inject your code onto the cms page. I've written a few articles on this alternative approach which can be found on my prestashop blog

Having codebehind for Custom .aspx page in sandbox solution

I am having working with sandbox solution. i have one .aspx page in my solution and i have placed one button tag in that page, i need to write server side code for that button. But it is showing "The event handler 'OnClick' is not allowed in this page." . Does codebehind is not allowed in sandbox solution. Or indirectly how can i write my c# code for that button.
I know we can do it by creating one webpart and show that webpart in page using "WebPartPages:SPUserCodeWebPart" tag . But i want to confirm whether we can write codebehind for an asp page in some way or not.
Without changing the web.config file (which would not be recommended in this case), inline code or code behind files are not supported outside of the layouts folder (which you cannot deploy to with a sandbox solution).
However, you should be able to create a class and then set the inherits attribute to point to that class, instead of referring to the class in a code behind file.

Finding page id of parent form from pop up form

I have two pages
Master page
page using the master page
I am opening a pop up using "window.open" in the second page.
I have textbox control in the second page and trying the find the control in the pop up page using below code.
window.opener.document.getElementById('textbox').value
This code could not found out the control.
Then I checked the page source of second form and dound out the format of control id. It was like below.
"_ctl0_ContentPlaceHolder1_textbox"
and changed the code to below and got success.
"window.opener.document.getElementById('_ctl0_ContentPlaceHolder1_textbox').value"
My query is -> I am not about this approach. Please correct if i am doing anything wrong.
With ASP.NET 4.0 you have the option to set ClientIDMode that could help you in this case.
Setting ClientIDMode to "Static" will ensure that your ID value will not be altered by the framework.
In your page where you have textbox:
<asp:TextBox ID="MyTextBox" runat="server" ClientIDMode="Static" />
Then you should be able to get the value by doing something like this:
window.opener.document.getElementById('textbox').value
Ref: MSDN - ClientIDMode
The problem is that if you use a masterpage the controls of your contentpage will be renamed making it hard to access them from JavaScript.
Use the following code to solve the problem:
<asp:TextBox ID="textbox" runat="server" ClientIDMode="Static"></asp:TextBox>

Keeping DRY with progressive enhancement

I'm building a website with very small amounts of Javascript, just to add things to the page (like a contact form) without having to go to a new page.
I understand that I should build the contact page anyways (just in case the user doesn't have javascript turned on) and then use javascript if they've got it.
So where do I store the HTML for the form if I don't want to have it in two places?
(Normally I'm not so picky, but I'm curious on this one.)
If you have access to a server-side language, you can keep a separate snippet of the form in an external page. Then, you can include the snippet into the HTML content page with an appropriate include call. This has the added benefit that, for your JavaScript, you can pull the contact form from this snippet file using AJAX. In fact, many plugins allow you to display DHTML windows with HTML content. For example, check out ThickBox.
Without a server-side language, you can do something similar with frames. Just display the form snippet in a frame when you need to reference it. Personally, I don't like frames very much, so this isn't a very attractive solution for me, but you can use it if you choose (and style the frames appropriately).
Just put your HTML for the contact form in a .html file. Assuming you're using PHP or something, just include the file in your contact page and include it in the section for your dynamic contact form. The form should still submit to the same server-side page and have the same look and feel..
e.g. contactForm.html
<div class="contact-form">
<input ....>
</div>