updateprogress control doesn't exist in the current context
Bonjour à tous,
J'essaye d'afficher l'état d'avancement d'un telechargement. Pour cela je procede comme cela (en gros)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
<asp:UpdateProgress runat="server" ID="UpdateProgress1" >
<ProgressTemplate>
<img id="myAnimatedImage" src="images/attente2.gif" alt="loading" width="24" height="24" />
<asp:Label ID="lblWait" runat="server" BackColor="#CC3300" Font-Bold="True" ForeColor="White" Text="Please wait ... Uploading file" />
<asp:Label runat="server" ID="LblDecompte" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UdPanel" runat="server" >
<ContentTemplate>
<asp:TextBox ID="FileUpload2" runat="server" style="width:450px;" />
<asp:Button ID="BtUploadPicture" runat="server" Text="Upload" OnClick="UploadPicture" OnClientClick="javascript:showWait('ctl00_cphContent_FileUpload2','ctl00_cphContent_UpdateProgress2');" />
</ContentTemplate>
</asp:UpdatePanel> |
Avec le code c#
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
|
protected void UploadFile(object src, EventArgs e)
{
//1- video file upload with exception management
if (FileUpload1.HasFile)
{
WebClient wc = new WebClient();
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(wc_DownloadDataCompleted);
wc.DownloadFileAsync(new Uri(TbVideoName.Text), TbDescription.Text);
}
}
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
LblDecompte.Text = e.ProgressPercentage.ToString() + "%";
System.Threading.Thread.Sleep(100);
}
void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
if ( ! e.Cancelled && e.Error == null )
LblDecompte.Text = "100%";
} |
Mais lorsque que je charge la page, j'ai
Citation:
The name 'LblDecompte' does not exist in the current context.
Je comprends pas pourquoi il ne le voit. Quand j'enleve les LblDecompte.Text de wc_DownloadDataCompleted et wc_DownloadProgressChanged. Il n'y a plus de problème mais du coup pas possible de faire le décompte.
Merci pour votre aide.