[CLOSED] FileUploadField issue

  1. #1

    [CLOSED] FileUploadField issue

    Hi,

    I need to use FileUploadField control inside a user control which is loaded on demand.

    Here is my test code:

    I have 1 aspx page, called Test.aspx and 1 user control, called TestControl.ascx. They are in the same root folder.

    Test.aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="XnCRS.UI.Test" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Test</title>
        <script runat="server">
           protected void ShowWindowClick(object sender, DirectEventArgs e)
           {
              EditPlaceHolder.ContentControls.Clear();
              EditPlaceHolder.ContentControls.Add(LoadControl("~/TestControl.ascx"));
              EditPlaceHolder.Render();
              WinAttach.Show();
           }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
          <ext:Button ID="btnShow" runat="server" Text="Show Upload File Window">
             <DirectEvents>
                <Click OnEvent="ShowWindowClick"></Click>
             </DirectEvents>
          </ext:Button>
        <ext:Window
            ID="WinAttach"
            runat="server"
            Title="Add an Attachment to Contract"
            Modal="true"
            Width="520"
            Height="160" Hidden="true">
            <Items>
              <ext:FitLayout ID="FitLayout1" runat="server">
                <Items>
                   <ext:Panel runat="server" ID="EditPlaceHolder" Border="false" BodyBorder="false"
                      ApplyTo="#{editWindow}">
                   </ext:Panel>
                </Items>
             </ext:FitLayout>
                
            </Items>
        </ext:Window>
        </form>
    </body>
    </html>
    And TestControl.ascx:
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="XnCRS.UI.TestControl" %>
    <script runat="server">
       protected void UploadClick(object sender, DirectEventArgs e)
       {
          string tpl = "Uploaded file: {0}<br/>Size: {1} bytes";
    
          if (this.FileUploadField1.HasFile)
          {
             X.Msg.Show(new MessageBoxConfig
             {
                Buttons = MessageBox.Button.OK,
                Icon = MessageBox.Icon.INFO,
                Title = "Success",
                Message = string.Format(tpl, this.FileUploadField1.PostedFile.FileName, this.FileUploadField1.PostedFile.ContentLength)
             });
          }
          else
          {
             X.Msg.Show(new MessageBoxConfig
             {
                Buttons = MessageBox.Button.OK,
                Icon = MessageBox.Icon.ERROR,
                Title = "Fail",
                Message = "No file uploaded"
             });
          }
       }
    </script>
    <ext:FormPanel
                    ID="BasicForm"
                    runat="server"
                    Width="500"
                    Title="File Upload Form"
                    PaddingSummary="10px 10px 0 10px"
                    LabelWidth="50">               
                    <Defaults>
                        <ext:Parameter Name="anchor" Value="95%" Mode="Value" />
                        <ext:Parameter Name="allowBlank" Value="false" Mode="Raw" />
                        <ext:Parameter Name="msgTarget" Value="side" Mode="Value" />
                    </Defaults>
                    <Items>
                        <ext:TextField ID="PhotoName" runat="server" FieldLabel="Name" />
                        <ext:FileUploadField
                            ID="FileUploadField1"
                            runat="server"
                            EmptyText="Select an image"
                            FieldLabel="Photo"
                            ButtonText=""
                            Icon="ImageAdd">
                        </ext:FileUploadField>
                    </Items>
                    <Listeners>
                        <ClientValidation Handler="#{SaveButton}.setDisabled(!valid);" />
                    </Listeners>
                    <Buttons>
                        <ext:Button ID="SaveButton" runat="server" Text="Save">
                            <DirectEvents>
                                <Click
                                    OnEvent="UploadClick"
                                    Before="if (!#{BasicForm}.getForm().isValid()) { return false; }
                                        Ext.Msg.wait('Uploading your photo...', 'Uploading');"
                                          
                                    Failure="Ext.Msg.show({
                                        title   : 'Error',
                                        msg     : 'Error during uploading',
                                        minWidth: 200,
                                        modal   : true,
                                        icon    : Ext.Msg.ERROR,
                                        buttons : Ext.Msg.OK
                                    });">
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:Button ID="Button1" runat="server" Text="Reset">
                            <Listeners>
                                <Click Handler="#{BasicForm}.getForm().reset();" />
                            </Listeners>
                        </ext:Button>
                    </Buttons>
                </ext:FormPanel>
    When i ran the application, i can show the dialog BUT CANNOT upload a file.

    Please give your help :)
    Thank you.
    Last edited by Daniil; Jan 20, 2011 at 9:49 AM. Reason: [CLOSED]
  2. #2
    Hi,

    The problem is the following thing - SaveButton control is not exist during DirectEvent request (you could see this response using FireBug or Fiddler). But DirectEvent requires control.

    Generally speaking, if you want to handle control during DirectEvent, this control must be exist.

    So, you have to recreate user control (for example, in Page_Load).
  3. #3
    Hi Daniil,

    Actually the issue i want to mention here is that: i cannot get the file being uploaded on the server. Sorry i did not mention it before.

    Look at the image below:



    I monitored the data posted back to the server. As you can see, the only control being posted back was PhotoName. I really want to get back the Photo.

    The actual issue i want to mention is: FileUploadField control.
  4. #4
    Thank for the details.

    Please set IsUpload="true" for DirectEvent.

    Example
    <ext:Button ID="SaveButton" runat="server" Text="Save">
        <DirectEvents>
            <Click
                OnEvent="UploadClick"
                IsUpload="true"
                Before="if (!#{BasicForm}.getForm().isValid()) { return false; }
                    Ext.Msg.wait('Uploading your photo...', 'Uploading');"
                       
                Failure="Ext.Msg.show({
                    title   : 'Error',
                    msg     : 'Error during uploading',
                    minWidth: 200,
                    modal   : true,
                    icon    : Ext.Msg.ERROR,
                    buttons : Ext.Msg.OK
                });">
            </Click>
        </DirectEvents>
    </ext:Button>
  5. #5
    Hi Daniil,

    It works. And my app runs well now.

    Thank you so much.

Similar Threads

  1. [CLOSED] FileUploadField browse button issue
    By Daly_AF in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 28, 2012, 4:44 PM
  2. Replies: 4
    Last Post: Apr 24, 2012, 11:59 AM
  3. [CLOSED] [1.0] FileUploadField timeout issue
    By ljankowski in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 27, 2010, 5:04 PM
  4. [CLOSED] FileUploadField issue...
    By shahidmughal in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 29, 2010, 3:07 PM
  5. [CLOSED] FileUploadField issue
    By egodoy in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Oct 15, 2009, 12:17 PM

Tags for this Thread

Posting Permissions