Précédent   Forum des professionnels en informatique > Dotnet > Développement Web avec .NET > ASP.NET
ASP.NET ASP.NET -Forum d'entraide sur le Développement Web en ASP.NET. Avant de poster -> FAQ ASP.NET, Articles ASP.NET
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 27/01/2012, 16h17   #1
Invité régulier
 
Inscription : août 2006
Messages : 104
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 104
Points : 8
Points : 8
Par défaut Problème AsyncFileUpload renvoi le fichier

Bonjour,

Je n'arrive pas à vider le composant lorsque le fichier est chargé.

Si j'ai un autre bouton sur la page, il renvoie à nouveau le fichier.

Merci pour votre aide.
Scots est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2012, 17h24   #2
Invité régulier
 
Inscription : août 2006
Messages : 104
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 104
Points : 8
Points : 8
J'ai testé une fonction que j'ai trouvée sur internet :

Code :
1
2
3
4
5
6
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        string filename = ConfigurationManager.AppSettings["URLDocument"] + AsyncFileUpload1.PostedFile.FileName;
        AsyncFileUpload1.SaveAs(filename);
        Page.Controls.Remove(AsyncFileUpload1);
    }
Hélàs sans succès. Même avec la partie javascript
Scots est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2012, 17h29   #3
Membre émérite
 
Homme John Doe
Développeur .NET
Inscription : novembre 2010
Messages : 549
Détails du profil
Informations personnelles :
Nom : Homme John Doe
Localisation : France, Rhône (Rhône Alpes)

Informations professionnelles :
Activité : Développeur .NET

Informations forums :
Inscription : novembre 2010
Messages : 549
Points : 824
Points : 824
c'est quoi ton code d'envoi ?
youtpout978 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2012, 17h34   #4
Invité régulier
 
Inscription : août 2006
Messages : 104
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 104
Points : 8
Points : 8
Le code aspx :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test-Components.aspx.cs" Inherits="Test_Components" %>
 
<!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></title>
    <script type = "text/javascript">
        function uploadComplete(sender) {
            $get("activity").style.visibility = 'hidden';
            $get("<%=lblMesg.ClientID%>").innerHTML = "Chargement de votre pièce jointe réussi.";
               //Clear the file name textbox
 
           var ctrlText = sender.get_element().getElementsByTagName("input");
           for (var i = 0; i < ctrlText.length; i++) {
              if (ctrlText[i].type == "text") {
                 ctrlText[i].value = "";
                 ctrlText[i].style.backgroundColor = "white";
              }
           }
        }
        function uploadError(sender) {
            $get("<%=lblMesg.ClientID%>").innerHTML = "Erreur pendant le chargement.";
        }
        function uploadStarted(sender) {
            $get("AsyncFileUpload1").style.visibility = 'hidden';
        }
    </script>     
</head>
<body>
    <form id="form1" runat="server">
    <ajaxToolkit:ToolkitScriptManager runat="server" />
    <div>
        <ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" runat="server" 
            ViewStateMode="Enabled" ThrobberID="activity" 
            onuploadedcomplete="AsyncFileUpload1_UploadedComplete" 
            onuploadedfileerror="AsyncFileUpload1_UploadedFileError" 
            CompleteBackColor="Lime" ErrorBackColor="Red" OnClientUploadError="uploadError" 
            OnClientUploadComplete="uploadComplete" OnClientUploadStarted="uploadStarted" 
            PersistFile="True" />
        <img src="images/activity.gif" runat="server" id="activity" alt="Chargement en cours ..." title="Chargement en cours ..." />
        <br /> 
        <asp:Label ID="lblMesg" runat="server" Text="" />
        <br /><br />
        <asp:Button ID="Button1" runat="server" Text="Sauvegarder" onclick="Button1_Click" />
        <br />
        <asp:Label ID="LbSauvegarde" runat="server" Text="Avant click" />
    </div>
    </form>
</body>
</html>
Le .cs :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
 
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
using System.Net.Mail;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using Bitly;
 
public partial class Test_Components : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        string filename = ConfigurationManager.AppSettings["URLDocument"] + AsyncFileUpload1.PostedFile.FileName;
        AsyncFileUpload1.SaveAs(filename);
        Page.Controls.Remove(AsyncFileUpload1);
    }
    protected void AsyncFileUpload1_UploadedFileError(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
 
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        LbSauvegarde.Text = "Après click";
    }
}
Scots est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2012, 21h26   #5
Membre émérite
 
Homme John Doe
Développeur .NET
Inscription : novembre 2010
Messages : 549
Détails du profil
Informations personnelles :
Nom : Homme John Doe
Localisation : France, Rhône (Rhône Alpes)

Informations professionnelles :
Activité : Développeur .NET

Informations forums :
Inscription : novembre 2010
Messages : 549
Points : 824
Points : 824
une technique pour effacer le contenu du contrôle j'espère ça t'aidera:
http://www.aspsnippets.com/Articles/...e-revisit.aspx
et dans ton upload completed dans le codebehind tu peux vérifier si il y a un fichier dedans avant de le sauvegarder avec
Code :
AsyncFileUpload1.HasFile
youtpout978 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2012, 22h18   #6
Invité régulier
 
Inscription : août 2006
Messages : 104
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 104
Points : 8
Points : 8
Merci Youtpout, je regarde ça demain et je te dirais si ça marche
Scots est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 17h02.


 
 
 
 
Partenaires

Hébergement Web