Jul 22, 2010, 5:14 PM
[CLOSED] Please help me with a fileupload question
I implemented my file upload dialog in a Window ->formPanel, using the example from example explorer. The only thing I did additional is to put below code in a window, When i click a button a window with fie upload dialog with come up. But when i hit save, if (this.FileUploadField1.HasFile) always returns nothing.
What should I do to make it work?
What should I do to make it work?
<ext:Window ID="WinAttach" runat="server" Title="Add an Attachment to Contract" Modal="true"
Hidden="true" ShowOnLoad="false" AutoShow="false" Width="520" Height="160">
<Items>
<ext:FormPanel
ID="BasicForm"
runat="server"
Width="500"
Frame="true"
Title="File Upload Form"
AutoHeight="true"
MonitorValid="true"
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 runat="server" Text="Reset">
<Listeners>
<Click Handler="#{BasicForm}.getForm().reset();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
</Items>
</ext:Window>
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"
});
}
}
Last edited by geoffrey.mcgill; Jul 22, 2010 at 6:09 PM.
Reason: please use [code] tags