Bonjour,
J'essaye de m'entraîner en ASP.NET AJAX et je teste les principaux composants serveur de base de ASP.NET AJAX (ScriptManager, UpdatePanel, UpdateProgress, Timer ..).
Je m'entraine à l'aide d'un tutorial dont je ne retrouve plus le lien mais peu importe.
Voici mon code :
La classe .aspx :
p01_ExempleAJAX.aspx
Et la page aspx.cs associée : (code behind)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
52
53
54
55
56
57
58
59
60
61
62
63 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="p01_ExempleAJAX.aspx.cs" Inherits="p01_ExempleAJAX" %> <!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>Un exemple d'utilisation d'Ajax</title> </head> <body> <form runat="server"> Page générée à : <asp:Label runat="server" ID="labelDate"></asp:Label> <br /><br /> <asp:ScriptManager runat="server" ID="monScriptManager" EnablePartialRendering="true"></asp:ScriptManager> <asp:UpdatePanel runat="server" ID="monUP"> <ContentTemplate> Dernier retour serveur à : <asp:Label runat="server" ID="labelUpdateDate"></asp:Label> <br /> Nombre de retours : <asp:Label ID="laCount" runat="server" Text="0"></asp:Label> <br /><br /> <asp:Button runat="server" ID="buUpdate" Text="Quelle heure est il ?" OnClick="buUpdate_Click" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="monTimer" EventName="Tick" /> </Triggers> </asp:UpdatePanel> <asp:UpdateProgress ID="monUpdateProgress" AssociatedUpdatePanelID="monUP" runat="server"> <ProgressTemplate> Traitement asynchrone en cours .. </ProgressTemplate> </asp:UpdateProgress> <asp:Timer ID="monTimer" runat="server" Interval="10000" OnTick="monTimer_Tick"></asp:Timer> Entrez un password <br /> <asp:TextBox ID="TextBox1" runat="server" Width="479px"></asp:TextBox> </form> </body> </html>
p01_ExempleAJAX.aspx.cs
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Threading; public partial class p01_ExempleAJAX : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { labelDate.Text = DateTime.Now.ToString(); labelUpdateDate.Text = DateTime.Now.ToString(); laCount.Text = (Convert.ToInt32(laCount.Text) + 1).ToString(); } protected void buUpdate_Click(object sender, EventArgs e) { Thread.Sleep(5000); labelUpdateDate.Text = DateTime.Now.ToString(); } protected void monTimer_Tick(object sender, EventArgs e) { labelUpdateDate.Text = DateTime.Now.ToString(); } }
Ma question est :
Pourquoi mon composant UpdateProgress n'affiche pas son contenu lors de chaque tic de mon Timer ?
Est ce une propriété normale ?
(Alors que le contenu de mon composant UpdateProgress s'affiche bien lorsque je clique sur mon bouton "Quelle heure est il ?" ...)
Merci de m'éclairer !!
Partager