UpdatePanel中的控件未更新

编程入门 行业动态 更新时间:2024-10-24 22:29:15
本文介绍了UpdatePanel中的控件未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用带有某些控件的UpdatePanel.当我单击按钮时,它会创建一个睡眠.这一次,我单击第二个按钮,其处理程序成功执行异步.但是其中一个标签不会更新.为什么?

< body > ; < 表单 id =" form1" runat =" 服务器" > < asp:ScriptManager ID =" ScriptManager1" runat =" 服务器" > < asp:UpdatePanel ChildrenAsTriggers =" true" ID =" UpdatePanel1 " runat =" 服务器" > < contenttemplate > < asp:Button 运行 =" 服务器" 文本 =" PostBackFirst " ID =" btnPostF" span> onclick =" btnPostF_Click" / > < asp:Button 运行 =" 服务器" 文本 =" PostBackSecond " ID =" btnPostS" span> onclick =" btnPostS_Click" / > < asp:Button 运行 =" 服务器" 文本 =" AbortPostBack " ID =" btnAbort" span> OnClientClick =" Sys.WebForms.PageRequestManager.getInstance().abortPostBack(); alert('回发已取消');" / > < asp:Label ID =" Label1" runat =" 服务器" 文本 =" " > < asp:Label ID =" Label2" runat =" 服务器" 文本 =" " > < /contenttemplate > < /form > < /body >

受保护的 void btnPostF_Click(对象发​​件人,EventArgs e) { System.Threading.Thread.Sleep( 4000 ); Label1.Text = " 回传1已完成" ; } 受保护的 无效 btnPostS_Click(对象发​​件人,EventArgs e) { System.Threading.Thread.Sleep( 4000 ); Label2.Text = " 回传2已完成" ; }

解决方案

我认为两个标签的autopostback = true都可以正常工作. /> 事情表现正常.让我解释一下它是如何工作的- 假设您单击第一个按钮,则单击事件是单击事件,它休眠4秒钟.现在,如果您在睡眠状态下通过单击第三个按钮来中止帖子,则可以.然后它将不会继续进行该事件.如果等待4秒钟,则可以看到标签已更新为所需的值.与第二个按钮相同.

I use an UpdatePanel with some controls. When I click on the button, it creates a sleep. In this time I click on second button, its handlers execute async successfully. But one of the labels does not get updated. Why?

<body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> <asp:UpdatePanel ChildrenAsTriggers="true" ID="UpdatePanel1" runat="server" > <contenttemplate> <asp:Button runat="server" Text="PostBackFirst" ID="btnPostF" onclick="btnPostF_Click"/> <asp:Button runat="server" Text="PostBackSecond" ID="btnPostS" onclick="btnPostS_Click"/> <asp:Button runat="server" Text="AbortPostBack" ID="btnAbort" OnClientClick="Sys.WebForms.PageRequestManager.getInstance().abortPostBack(); alert('Postback Cancelled');"/> <asp:Label ID="Label1" runat="server" Text=""> <asp:Label ID="Label2" runat="server" Text=""> </contenttemplate> </form> </body>

protected void btnPostF_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(4000); Label1.Text = "PostBack 1 Completed"; } protected void btnPostS_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(4000); Label2.Text = "PostBack 2 Completed"; }

解决方案

i think autopostback=true for the two labels will work fine..

Hi, Things are behaving correctly. Let me explain how it is working- Suppose you click on the first button, on click it comes to the click event and it sleeps for 4 seconds. Now while its in sleep if you abort the post back by clicking third button. Then it will not proceed with the event. If you wait for 4 second then you can see the label is updated with the desired value. Same with second button.

更多推荐

UpdatePanel中的控件未更新

本文发布于:2023-11-10 06:31:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   UpdatePanel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!