简体   繁体   English

我可以在UserControl的UpdatePanel中调用父级的事件方法吗?

[英]Can I call an event method of a parent from within an UpdatePanel on a UserControl?

I have the following scenario that I need to implement. 我有以下需要实现的方案。

I have a GridView with a list of records. 我有一个带有记录列表的GridView When a user selects a record, a pop-over screen appears within the browser showing the contents of the record. 当用户选择一条记录时,浏览器中会出现一个弹出屏幕,显示该记录的内容。 The contents are rendered from a UserControl , and within the UserControl there is an UpdatePanel that is used for loading/reloading data as it is manipulated and saved. 内容是从UserControl呈现的,并且在UserControl有一个UpdatePanel ,用于在操作和保存数据时加载/重新加载数据。

What I need to occur is that after each save on my UserControl , the GridView on the parent page needs to refresh as to reflect any changes on the record being shown in the pop-over editor control. 我需要发生的是,每次在UserControl上进行保存后,父页面上的GridView需要刷新,以反映弹出式编辑器控件中显示的记录上的任何更改。

My plan is to setup an event on my UserControl that the parent page will subscribe too. 我的计划是在UserControl上设置一个父页面也将订阅的事件。 When a save operation is executed from within the UserControl , it will call the event, and the parent page should update itself. 当从UserControl内部执行保存操作时,它将调用该事件,并且父页面应自行更新。

However, since the UserControl operates within an UpdatePanel , and is only doing a partial-postback, I am suspect that my events will not work properly. 但是,由于UserControlUpdatePanel ,并且仅执行部分回发,因此我怀疑我的事件将无法正常工作。

Should this work as I hope or will I need to find another way of telling my parent page to refresh the master GridView after a record is saved? 保存该记录后,是否应该按我希望的那样工作?还是需要找到另一种方法告诉我的父页面刷新主GridView

If I need to to call an update in a different manner, what is the best approach for this scenario? 如果我需要以其他方式调用更新,这种情况下最好的方法是什么? I ask because I'd rather not build-out some complex saving/updating operation only to find out that I've made a few miss-assumptions and need to re-code the whole update and reload process. 我之所以这样问是因为我不想进行一些复杂的保存/更新操作,只是为了发现我做了一些错误假设,并且需要重新编码整个更新和重新加载过程。

I have done that before I just don't remember exactly how as I haven't been working with Web Forms in a little while. 我已经做完了,直到我不记得确切的时间了,因为我已经有一段时间没有使用Web Forms了。 You have the right idea. 你有正确的主意。 The event will get raised on the parent page but you will have to do another PostBack/Partial PostBack afterwards to update the grid from the event handler on the parent. 该事件将在父页面上引发,但是您之后必须执行另一次PostBack / Partial PostBack才能从父事件处理程序中更新网格。 Also you will have to make sure the properties on the UpdatePanel have been set up right. 另外,您还必须确保UpdatePanel上的属性设置正确。

Another option is doing a full postback when you close the PopUp. 另一种选择是在关闭PopUp时执行完整的回发。 If the popup is big enough that it prevents the user from seeing the grid it wont make a difference whether the record on the grid is updated when the Modal is closed rather than when the data is saved. 如果弹出窗口足够大,以至于阻止用户看到网格,则在模式关闭时而不是在保存数据时,网格上的记录是否更新将无济于事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM