asp.net在timer .tick事件中显示标签 [英] asp.net dislpaying an label in timer .tick event

查看:64
本文介绍了asp.net在timer .tick事件中显示标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我的代码正在尝试通过更新面板中的计时器滴答事件来更新标签,但它似乎无法正常工作,或者我的while循环中断了,我们将不胜感激

这是我的设计,代码下方


Hi guys here is my code im trying to update a label with a timer tick event in an update panel but it doesnt seem to work or my while loop is broken any help would be appreciated

here is my design and below the code


@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="xp.WebForm1" %>

<!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 id="Head1" runat="server">
    <title></title>
</head>

<body>
    <form id="form1" runat="server">
          <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:Timer runat="server" id="UpdateTimer" interval="1000" ontick="UpdateTimer_Tick" />
        <asp:UpdatePanel runat="server" id="TimedPanel" updatemod">
            <Triggers>
                <asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
            </Triggers>
            <ContentTemplate>
                <asp:Label runat="server" id="DateStampLabel" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <div>
   <table>
<tr>
<td>
<span style="color: Red">*</span>Attach Excel file
</td>
<td>
<asp:FileUpload ID="fileuploadExcel" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSend" runat="server" Text="Export" onclick="btnSend_Click"  />
</td>
</tr>
</table>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>

            </div>
    </form>
</body>
</html>





using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.SessionState;
using System.Text;
using System.Threading;
using System.Timers;
namespace WebApplication2
{
    public partial class _Default : System.Web.UI.Page
    {

        int Time1 = 1;
        bool maxTime;
        System.Timers.Timer timer1 = new System.Timers.Timer();
        protected void Page_Load(object sender, EventArgs e)
        {
            while (maxTime==true)
            {
                Time1 = Time1 + 1;
            }
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            maxTime = true;
            
            <pre lang="cs">Response.Write("hallo");

            maxTime = false;

        }

        protected void UpdateTimer_Tick(object sender, EventArgs e)
        {

            DateStampLabel.Text = Time1.ToString();
            Time1++;
        }
    }
}

推荐答案

while (maxTime==true)
{
    Time1 = Time1 + 1;
}



这个while循环根本不起作用.因为页面加载时没有任何值,所以maxTime不会为真.



This while loop isn''t work at all.Because when your page loads,it don''t get any value.so maxTime will not true.


这篇关于asp.net在timer .tick事件中显示标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆