JavaScript的触发的UpdatePanel不更新正确 [英] JavaScript-Triggered UpdatePanel Not Updating Correctly
问题描述
我工作的一个大的,复杂的ASP.NET项目。
I'm working on a large, complex ASP.NET project.
我有一个不正确地更新一个UpdatePanel动态加载web用户控件。在UpdatePanel正在从一个JavaScript功能触发。
I have a dynamically loaded web user control with an UpdatePanel that doesn't update correctly. The UpdatePanel is being triggered from a JavaScript function.
我已经成功地创建一个展示这个问题非常简单的项目,并把它贴在 HTTP ://www.softcircuits.com/Client/TestProject.zip
I've managed to create a very simplified project that demonstrates the issue and have posted it at http://www.softcircuits.com/Client/TestProject.zip.
我将非常感激,如果有人用这些技术有更深的了解可以看看,并指出我朝着正确的方向发展。
I would be extremely grateful if someone with a deeper understanding of these technologies could take a look and point me in the right direction.
推荐答案
我想我找到发生了什么。我知道在UpdatePanel回发是像一个正常的回发,但只有在网页的一部分被发送回客户端。所以,我打了一下周围,发现什么HalfTrackMindMan提到的正常工作。然后我问谷歌约常见的错误与的UpdatePanel,发现这篇文章这说明了什么错误。
I think I found what is happening. I know that the UpdatePanel postback is like a normal postback but only a part of the page is sent back to the client. So I played around a bit and found what HalfTrackMindMan mentioned to work as expected. Then I asked google to about common mistakes with UpdatePanels and found this article that explained what is going wrong.
这是实际发生的事情。
This is what actually happens.
- __ doPostback后的页面到服务器的值
- 在参数后两个文本框的值是空白
- 在服务器上的负载事件被触发,你改变文本框的文本
- 在事件处理的执行和发布值在2文本框设置(它们都重新设置为空白
- ...
- 更新面板呈现空白值
所以,如果你把测试中的文本框和preSS的按钮,你可以看到测试的价值去到服务器,回来之一。
So if you put testing in one of the textboxes and press the button you can see that "testing" value goes to the server and comes back.
1|#||4|356|updatePanel|MainContent_WebUserControl11_ctl00_UpdatePanel1|
<p>
Message:<br />
<input name="ctl00$MainContent$WebUserControl11$ctl00$TextBox1" type="text" value="testing" id="MainContent_WebUserControl11_ctl00_TextBox1" />
</p>
所以,在你需要做的是在pre_render事件的最新面板更新输入元素的值。在另一方面,你可以更新ON_LOAD一个标签,它会工作。
So to update the values of input element in an update panel you need to do it in the Pre_render event. On the other hand you can update a label on on_load and it will work.
希望有所帮助。
这篇关于JavaScript的触发的UpdatePanel不更新正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!