Question

How can I show a message when the ext.net's FileUploadField complete. (With Javascript on clientside).

My code for using 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>
Was it helpful?

Solution

First solution (full client side):

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

Second solution (server side script generation):

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

And you can look here http://examples.ext.net/#/Form/FileUploadField/Basic/

OTHER TIPS

There are a few ways to do this.

A "cheap trick" approach is to add a blank literal to your page and update it's text during the onfileuploaded event (or whatever event you want) with the text needed to fire your javascript function. (Note that this approach only works if there's an actual page postback!)

Another approach (and considered the "correct" way) to manage this in ASP.NET is to add a scriptmanager to your page and register your clientscript with it in the onfileuploaded event (or whatever event you want). Code examples for those are numerous and easily google-able.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top