[英]ASP.net can't update page from event handler
i have a linkbutton on a page, the event hander for the click event of that button calls a method on an object which in turn makes a call to a webservice, when the webservice returns the object fires an event and an event handler on the page codebehind updates a label on the page.我在页面上有一个链接按钮,该按钮的单击事件的事件处理程序调用 object 上的一个方法,该方法反过来调用一个 Web 服务,当 Web 服务返回 object 时会在页面上触发一个事件和一个事件处理程序代码隐藏更新页面上的 label。 For some reason the label doesn't display the message.由于某种原因,label 不显示该消息。
This has been driving me crazy and i can't find anything about it on google.这一直让我发疯,我在谷歌上找不到任何关于它的信息。 any help would be appriciated.任何帮助都会得到帮助。
The webservice is being called asynchronously but the thread is being blocked until it returns.正在异步调用 Web 服务,但线程被阻塞,直到它返回。 and the labels pre render event is being called after its text is being set by the proxy objects event handler.并且标签预渲染事件在其文本由代理对象事件处理程序设置后被调用。
All the calls are happening on the same thread, any values i set,not just the label text, in the event handler are getting reverted to their previous values by the time the pre-render event fires.所有调用都发生在同一个线程上,我设置的任何值,而不仅仅是 label 文本,在预渲染事件触发时,事件处理程序中的值都将恢复为之前的值。
Here's what's happening:这是正在发生的事情:
Update:更新:
The OP updated his question after I posted this to indicate that the life cycle timing is kept in sync. OP 在我发布此问题后更新了他的问题,以表明生命周期时间保持同步。 So instead, I'll point out that controls in ASP.Net are not threadsafe, but the webservice completed event is called from the thread used in the background to make the asynchronous request rather than the originating thread.因此,相反,我将指出 ASP.Net 中的控件不是线程安全的,而是从后台使用的线程调用 webservice 完成事件以发出异步请求,而不是从源线程调用。 You should Invoke
the control when setting the property.您应该在设置属性时Invoke
控件。
Have you got this in your Page_Load event?你在你的 Page_Load 事件中有这个吗?
if (Page.IsPostBack)
{
return;
}
If not, the label can be re-initialized after the postback.如果没有,label 可以在回发后重新初始化。
Is the webservice running asynchronously?网络服务是否异步运行? Maybe the webservice complete event fires after the page has been rendered?页面渲染后可能会触发 web 服务完成事件? Have you debugged to make sure the label value is being set?您是否已调试以确保正在设置 label 值?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.