我的代码有问题吗? [英] Is there something wrong with my code?

查看:107
本文介绍了我的代码有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格,我想每隔X秒绑定一次,但是计时器不会等到进程完成,它只是一遍又一遍地执行,我甚至尝试创建一个变量,并将其用作标志,但它似乎没有工作,这里是我的代码(问题不在我的代码背后,如果它有任何问题必须在这里,因为我唯一要做的是在tick事件中绑定网格):



I have a grid that I want to bind every X seconds, but the timer is not waiting until the process is done, it's just executing itself over and over, I even tried creating a variable, and use it as a flag, but it doesn't seem to be working, here is my code(the problem is not in my code behind, if there's any problem it has to be here, because the only thing i do is bind the grid in the tick event):

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Talk1Rep._Default" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
      <asp:ScriptManager runat="server" ID="ScriptManager1">
        <Scripts>
            <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=272931&clcid=0x409 --%>
            <%--Framework Scripts--%>
            
            <asp:ScriptReference Name="MsAjaxBundle" />
            <asp:ScriptReference Name="jquery" />
            <asp:ScriptReference Name="jquery.ui.combined" />
            <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
            <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
            <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
            <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
            <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
            <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
            <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
            <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
            <asp:ScriptReference Name="WebFormsBundle" />
            <%--Site Scripts--%>

        </Scripts>
    </asp:ScriptManager>
    <section class="featured">
      <div>
        <table style="width:100%;">
            <tr>
                    
                 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"  ViewStateMode="Enabled">
                   
                   <Triggers>
                              <asp:AsyncPostBackTrigger  ControlID="Timer1" EventName="Tick" />
                        </Triggers>
                        <ContentTemplate>
                            
                            <asp:GridView ID="gv_stats" runat="server" AutoGenerateColumns="False" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" ForeColor="Black" ShowHeaderWhenEmpty="True" Width="100%" OnRowDataBound="gv_stats_RowDataBound" ShowFooter="True" EnableViewState="False" CellSpacing="2" > my gridview
                            </asp:GridView>
                            <hr />
                            <asp:Label ID="Label1" runat="server" Text="Last Update: "></asp:Label>
                            <asp:Label ID="lbl_lastUpdate" runat="server"></asp:Label>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                   <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" EnableViewState="True">
                    </asp:Timer>
                </td>
            </tr>
        </table>
        </div>
    </section>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    </asp:Content>
<asp:Content ID="Content1" runat="server" contentplaceholderid="HeadContent">

</asp:Content>

推荐答案

你能查看一个标志吗?你的Timer1_Tick()

- >如果为true GetLatestDataForGrid()

- >否则忽略

- >设置flag = False



并在完成gridLoad后将该标志设置为TRUE。
Can you check a flag in your Timer1_Tick()
-> If true GetLatestDataForGrid()
-> Else ignore
-> Set flag=False

And set that flag to TRUE after completion of your gridLoad.


这篇关于我的代码有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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