【问题标题】:Classes conflict when i use Timer with updatePanal当我将 Timer 与 updatePanal 一起使用时,类冲突
【发布时间】:2016-08-10 20:12:40
【问题描述】:

我正在尝试使用 updatePanal 作为此代码构建 asp.net 应用程序:

      <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                    <asp:Timer runat="server" id="Timer1" Interval="10000" OnTick="Timer1_Tick"></asp:Timer>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
     <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
    <ContentTemplate>

            <div class="col-xs-6 col-md-3">
                <div class="panel panel-default">
                    <div class="panel-body easypiechart-panel">
                        <h4>Humidity </h4>
                        <div   class="easypiechart" id="easypiechart-blue" data-percent="4" ><span class="percent">92%</span>
                        </div>
                                                                            <button class="btn btn-primary">Adjust Humidity</button><br /><br /><br />

                    </div>
                </div>
            </div>
        </ContentTemplate>
            </asp:UpdatePanel>

在更新之前这是我的 div ! :

更新后变成这样:

为什么会这样?

【问题讨论】:

    标签: asp.net asp.net-ajax updatepanel


    【解决方案1】:

    您可能必须在计时器滴答时再次调用构建 easypiechart 的 javascript 函数。

    protected void Timer1_Tick(object sender, EventArgs e) 
    {
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "buildPie", "YourBuildPieFunction();", true);
    }
    

    更新

    首先,您的代码不完整。在您发布在 cmets 中的 javascript 中,您有 document.getElementById('percentH').innerText = percentage + "%"; 行。但是“percentH”不存在。 &lt;span&gt; 元素的 ID 必须为 &lt;span id="percentH" class="percent"&gt;92%&lt;/span&gt;

    其次,饼图不是由该代码构建的。如果你使用https://rendro.github.io/easy-pie-chart/ 或类似的东西,页面上的某处应该是这样的:

    $(function() {
        $('.easypiechart').easyPieChart({
            //your configuration goes here
        });
    });
    

    这是需要被ScriptManager调用的javascript代码部分。

    【讨论】:

    • 我已经尝试过了,只用了按钮,`ClientScript.RegisterStartupScript(this.GetType(), "updateProgress", "updateProgress('" + 100 + "');", true ); ` 但还是同样的错误!
    • 我刚刚用一个类似的饼图进行了测试,它的代码可以工作,饼图在更新面板内的定时器刷新或按钮点击后重建。您能否将构建饼图的 javascript 代码添加到您的问题中?
    • 我使用这个函数 updateProgress(percentage) { document.getElementById('easypiechart-blue').setAttribute("data-percent", percent); document.getElementById('precentH').innerText = 百分比 + "%";它可以在没有 updatepanl 的情况下工作,但是当我使用它时,它不起作用,知道吗?
    • 你能澄清一下吗@VDWWD
    • 如果您可以发布所有有助于查找的 javascipt 代码和脚本源( 等)解决方案
    猜你喜欢
    • 2011-07-07
    • 1970-01-01
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 2015-07-29
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多