2011-10-09 82 views
2

如何在ext.net的FileUploadField完成时显示消息。 (与客户方的JavaScript)在Ext.net(ASP.NET)中上传完成事件?

我使用ext.net UploadField代码

<script type="text/javascript"> 
    function checkExtension(value) { 
     if (value.match("\.png$") != null || value.match("\.jpg$") != null 
     || value.match("\.jpeg$") != null || value.match("\.gif$") != null) 
      return true; 
     alert("The file must be image"); 
     return false; 
    } 
</script> 

<ext:FileUploadField ID="FileUploadField1" runat="server" Icon="Attach" ButtonText="Select File" Visible="true" ButtonOffset="1" ButtonOnly="true" Validator="checkExtension"> 
    <DirectEvents> 
     <FileSelected OnEvent="ImageFileSelected" /> 
    </DirectEvents> 
</ext:FileUploadField> 
+0

我还没有使用ext.net,但我可以帮助你使用YUI上传。看看这里'http:// labs.deeptechtons.com/asp-net-tuts/how-to-upload-files-asynchronously-using-yahoo-uploader /' – Deeptechtons

回答

2

第一溶液(全客户端):

<ext:FileUploadField ID="FileUploadField1" runat="server" Icon="Attach" ButtonText="Select File" Visible="true" ButtonOffset="1" ButtonOnly="true" Validator="checkExtension"> 
    <DirectEvents> 
     <FileSelected OnEvent="ImageFileSelected" 
       Success="Ext.Msg.alert('Success');" 
       Failure="Ext.Msg.alert('Failure');" /> 
    </DirectEvents> 
</ext:FileUploadField> 

第二种解决方案(服务器端脚本生成):

public void ImageFileSelected(object sender, DirectEventArgs e) { 
    if (this.FileUploadField1.HasFile) { 
     // save file here 

     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) 
     }); 
    } 
} 

而且你可以看看这里http://examples.ext.net/#/Form/FileUploadField/Basic/

1

有几个方法可以做到这一点。

“廉价技巧”的方法是在您的页面中添加一个空白字面并在onfileuploaded事件(或任何您想要的事件)期间更新它的文本,并使用启动JavaScript函数所需的文本。 (请注意,如果有一个实际的网页提交这种方法只适用!)

另一种方法(和认为是“正确”的方式)在ASP.NET来管理这是一个ScriptManager添加到您的页面并注册clientscript与onfileuploaded事件(或任何你想要的事件)。对于那些代码例子很多,容易google-able.