Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP具有GridView的多个UpdatePanel,但只有一个更新_C#_Asp.net_Asp.net Ajax - Fatal编程技术网

C# ASP具有GridView的多个UpdatePanel,但只有一个更新

C# ASP具有GridView的多个UpdatePanel,但只有一个更新,c#,asp.net,asp.net-ajax,C#,Asp.net,Asp.net Ajax,我希望在单个aspx页面上有3个GridView,由单个DB查询提供(显示静态数据,无需操作),并基于10秒计时器刷新表。我有返回已排序的数据表的代码。我可以让它更新我的一个更新面板中的一个gridview,但其他两个不渲染 代码是: <%@ Page Title="Index" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="T

我希望在单个aspx页面上有3个GridView,由单个DB查询提供(显示静态数据,无需操作),并基于10秒计时器刷新表。我有返回已排序的数据表的代码。我可以让它更新我的一个更新面板中的一个gridview,但其他两个不渲染

代码是:

<%@ Page Title="Index" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="Test.Admin" %>
<script runat="server" type="text/c#">
    protected void Page_PreRender(object sender, EventArgs e)
    {
        Label1.Text = "Panel refreshed at: " + DateTime.Now.ToLongTimeString();
        FullAccessSession.DataSource=GetStatus("FullAccess");
        FullAccessSession.DataBind();

        Label2.Text = "Panel refreshed at: " + DateTime.Now.ToLongTimeString();
        LimitedAccessSession.DataSource=GetStatus("LimitedStatus");
        LimitedAccessSession.DataBind();

        Label3.Text = "Panel refreshed at: " + DateTime.Now.ToLongTimeString();
        LogData.DataSource = GetLog() ;
        LogData.DataBind();

    }

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        Label1.Text = "Panel refreshed at: " + DateTime.Now.ToLongTimeString();
        FullAccessSession.DataSource=GetStatus("FullAccess");
        FullAccessSession.DataBind();

    }

    protected void Timer2_Tick(object sender, EventArgs e)
    {
        Label3.Text = "Panel refreshed at: " + DateTime.Now.ToLongTimeString();
        LogData.DataSource = GetLog() ;
        LogData.DataBind();
    }

    protected void Timer3_Tick(object sender, EventArgs e)
    {
        Label2.Text = "Panel refreshed at: " + DateTime.Now.ToLongTimeString();
        LimitedAccessSession.DataSource=GetStatus("LimitedStatus");
        LimitedAccessSession.DataBind();
    }



</script>

受保护的无效页面\u预呈现(对象发送方,事件参数e)
{
Label1.Text=“面板刷新时间:”+DateTime.Now.ToLongTimeString();
FullAccessSession.DataSource=GetStatus(“FullAccess”);
FullAccessSession.DataBind();
Label2.Text=“面板刷新时间:”+DateTime.Now.ToLongTimeString();
LimitedAccessSession.DataSource=GetStatus(“LimitedStatus”);
LimitedAccessSession.DataBind();
Label3.Text=“面板刷新时间:”+DateTime.Now.ToLongTimeString();
LogData.DataSource=GetLog();
LogData.DataBind();
}
受保护的无效计时器1_刻度(对象发送方,事件参数e)
{
Label1.Text=“面板刷新时间:”+DateTime.Now.ToLongTimeString();
FullAccessSession.DataSource=GetStatus(“FullAccess”);
FullAccessSession.DataBind();
}
受保护的无效计时器2_刻度(对象发送方、事件参数e)
{
Label3.Text=“面板刷新时间:”+DateTime.Now.ToLongTimeString();
LogData.DataSource=GetLog();
LogData.DataBind();
}
受保护的无效计时器3_刻度(对象发送方、事件参数e)
{
Label2.Text=“面板刷新时间:”+DateTime.Now.ToLongTimeString();
LimitedAccessSession.DataSource=GetStatus(“LimitedStatus”);
LimitedAccessSession.DataBind();
}









我不明白为什么我的一个更新面板工作。正如您所看到的,我已经尝试使用PreRender函数以及(当前已注释掉的)计时器。标签将随当前时间更新,但仅显示一个gridview

任何帮助都将不胜感激
谢谢

这里的问题是,在UpdatePanel内返回帖子后,计时器的脚本丢失了-解决方案是将其从更新面板中取出并使用触发器

下面是一个例子,我测试了它,并且工作正常

<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="2800"></asp:Timer>
<asp:Timer ID="Timer2" runat="server" ontick="Timer2_Tick" Interval="2500"></asp:Timer>

<div>
    <div>
    <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer1"  />
        </Triggers>

        <ContentTemplate>                   
            <asp:Literal runat="server" ID="txtTest1"></asp:Literal>
        </ContentTemplate>
    </asp:UpdatePanel>
    </div>

    <div>
    <asp:UpdatePanel runat="server" ID="UpdatePanel2" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer2"  />
        </Triggers>

        <ContentTemplate>
            <asp:Literal runat="server" ID="txtTest2"></asp:Literal>
        </ContentTemplate>    
    </asp:UpdatePanel>
    </div>
</div>

感谢@Aristos,我已经实现了这一点,它工作了一秒钟,然后从自动生成的javascript中抛出一个javascript错误。我在fault
\u endPostBack:function(n,t,I){var r,u,f;if(this.\u request==t.get\u webRequest()&&(this.\u processingRequest=!1,this.\u additionalInput=null,this.\u request=null),r=this.\u get\u eventHandlerList().getHandler(“endRequest”),u=!1,r&(f=new Sys.WebForms.EndRequestEventArgs)(n,i?i.dataItems:{},t),r(this,f),u=f.get_errorHandled()),n&&!u)throw n;}
错误是:
中第1行第123034列的未处理异常http://localhost:57789/bundles/MsAjaxJs?v=c42ygB2U07n37m_Sfa8ZbLGVu4Rr2gsBo7MvUEnJeZ81  0x800a139e-JavaScript运行时错误:Sys.WebForms.PageRequestManagerServerErrorException:对象引用未设置为对象的实例。
它仅在计时器t之后发生icks overOk,你可以忽略我的最后2条评论,我想我已经修复了这个bug。我已经修复了这个bug。我明天会再次查看它。这是问题的关键,经过一些修改,我已经能够在我的场景中实现这一点。感谢你们的帮助!
<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="2800"></asp:Timer>
<asp:Timer ID="Timer2" runat="server" ontick="Timer2_Tick" Interval="2500"></asp:Timer>

<div>
    <div>
    <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer1"  />
        </Triggers>

        <ContentTemplate>                   
            <asp:Literal runat="server" ID="txtTest1"></asp:Literal>
        </ContentTemplate>
    </asp:UpdatePanel>
    </div>

    <div>
    <asp:UpdatePanel runat="server" ID="UpdatePanel2" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer2"  />
        </Triggers>

        <ContentTemplate>
            <asp:Literal runat="server" ID="txtTest2"></asp:Literal>
        </ContentTemplate>    
    </asp:UpdatePanel>
    </div>
</div>
protected void Timer1_Tick(object sender, EventArgs e)
{
    txtTest1.Text += "1.";
}