如何通过 ContentPage 上的按钮更新 Masterpage 上的 GridView?
我有一个 MasterPage,在 UpdatePanel 上有一个 GridView。在我的内容页面之一上,我有一个按钮,它将项目添加到会话中,我希望该项目出现在 MasterPage 上的 Gridview 中。我在 Gridview 中获得了项目,但在刷新或回发或类似问题上遇到问题。有人对此有答案吗?
I have a MasterPage with a GridView on a UpdatePanel. On one of my content pages I have a button which adds items to a session which I want to appear in the Gridview which is on the MasterPage. I'v got the items in the Gridview but have problem with refresh or postback or something like that. Does anyone have an answere to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在更新面板中遇到刷新问题,则意味着回发按钮不在更新面板内,或者面板未手动更新。
对于这种情况,我假设您不能将按钮放在面板内,因为它是内容页面的一部分,因此我建议您将面板的 UpdateMode 设置为条件,并在母版页上使用一些刷新方法。为了在内容页面中看到此方法,请使用此方法创建一些接口,并让母版页使用此接口。
然后在内容页面中获取母版页引用并使用刷新方法。
例如
界面
母版页
(注意它使用我们之前创建的IMaster界面)
内容页面
If you have refresh issue in updatepanel, then it means that the post back button is aether not inside the update panel or the panel is not updated manually.
For this case I assume you cant put the button inside the panel as it is part of content page, so i suggest you set panel's UpdateMode to conditional and have some refresh method on your masterpage. In order to see this method in the content page make some Interface with this method and let the masterpage use this interface.
then in the content page take the masterpage referense and consume the refresh method.
e.g.
The interface
The masterpage
(note it uses the IMaster interface that we created before)
The content page
您需要研究使用事件和委托。基本上,您将在用户控件上创建一个事件,您的母版页将对此做出反应。还有许多其他网站提供示例,因此只需 google ASP.NET Events and Delegates 即可。
You will need to look into using Events and Delegates. Basically, you will create an Event on the Usercontrol which your MasterPage will react to. There are many other websites with examples, so just google ASP.NET Events and Delegates.