在論壇中,常常會看到30秒後才能按的按鈕,這個功能可以透過Ajax快速完成
在論壇中,常常會看到30秒後才能按的按鈕,最近在藍色小舖上有人詢問此問題,這個按鈕其實可以透過Ajax的Timer來做到,以下為程式碼
01 <html xmlns="http://www.w3.org/1999/xhtml">
02 <head id="Head1" runat="server">
03 <title></title>
04 </head>
05 <body>
06 <form id="form1" runat="server">
07 <asp:ScriptManager ID="ScriptManager1" runat="server">
08 </asp:ScriptManager>
09 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
10 <ContentTemplate>
11 <asp:Button ID="Button1" runat="server" Enabled="False" Text="30" OnClick="Button1_Click" />
12 </ContentTemplate>
13 <Triggers>
14 <asp:AsyncPostBackTrigger ControlID="Timer1" />
15 </Triggers>
16 </asp:UpdatePanel>
17 <div>
18 </div>
19 <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
20 </asp:Timer>
21 </form>
22 </body>
23 </html>

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

執行結果