Updatepanel未更新多个面板中的多个标签



好吧,希望是一个简单的

当在每个更新面板上调用更新时,标签不会在此处更新,只有在完成时才起作用,

脚本管理不是母版页,也已经允许部分渲染了。但仍然不起作用,有什么想法吗?我试图做的事情不正确吗?

请不要只是发布一个链接,实际告诉我哪里出了问题。我对更新面板的理解不正确吗?我怎样才能做到这一点?感谢

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div>
<asp:Button runat="server" ID="button1" OnClick="button1_Click" />
</div>
<asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="label1UP1" Text="This is the first label"></asp:Label>
</ContentTemplate>
<%--        <Triggers>
<asp:PostBackTrigger ControlID="button1" />
</Triggers>--%>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" ID="UP2" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="label1UP2" Text="This is the second label label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" ID="UP3" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="label1UP3" Text="This is the third label label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>  
</asp:Content>

protected void button1_Click(object sender, EventArgs e)
{
ViewState["el"] = methodone();
label1UP1.Text = ViewState["el"].ToString();
label1UP1.DataBind();
up1.Update();

System.Threading.Thread.Sleep(10000);
string label2 = methodtwo();
label1UP2.Text = label2.ToString();
label1UP2.DataBind();
UP2.Update();
System.Threading.Thread.Sleep(10000);
string label3 = methothree();
label1UP3.Text = label3.ToString();
label1UP3.DataBind();
UP3.Update();
}

这就是您需要做的:

  1. 使用javascript延迟回发三次例如:

    `

    <script>
    function callBackend(labelValue){
    document.getElementById("HLabelName").value = labelValue;
    __doPostBack("HLabelName", ""); //This causes a postback
    } 
    </script>
    <asp:HiddenField runat="server" ID="HLabelName"  OnValueChanged="HLabelName_OnValueChanged" ClientIDMode="Static"/>
    

`2.每次设置一个hiddenfield值以标识要更新的标签3.在后端事件中,获取hiddenfield值并更新相应的标签

在后端:

//This triggers the first event
protected void button1_Click(object sender, EventArgs e)
{
//Then call JS function to update label1
//This triggers the second event
ScriptManager.RegisterStartupScript(this, GetType(), "CallLabel3", "setTimeout(callBackend('label2'), 3000)", true);
}
protected void HLabelName_OnValueChanged(object sender, EventArgs e)
{
switch (this.HLabelName.Value)
{
case "label2":
//Update Label 2 here Value here

//This triggers the third event
//Then call JS function to update label3
ScriptManager.RegisterStartupScript(this, GetType(), "CallLabel3", "setTimeout(callBackend('label3'), 3000)", true);
break;
case "label3":
//Update Label 3 here
break;
}
}

这应该为你做的技巧

最新更新