如何通过单击母版页按钮来调用内容页面方法 [英] How to call content page methods by clicking master page button

查看:88
本文介绍了如何通过单击母版页按钮来调用内容页面方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含保存按钮和取消按钮的母版页面。应该执行我在内容页面中编写的代码(在我的所有内容页面中,我计划继承一个具有Save()和Cancel()方法的接口,因此Save和Cancel方法将在所有页)。



因此,我必须通过点击母版页按钮来执行我的Page Level功能[Save()]。



请帮助我实现这一功能。



提前致谢。

I have a Master page that contains save button and cancel button. It should be executed the code which I am writing in the content page( In all my content page, i am planning to inherit an interface which is having Save() and Cancel() methods, so Save and Cancel method will be there in all pages).

So, I have to execute my Page Level function [Save()] from the click of master page button.

Please assist me anyone to achieve this functionality.

Thanks in advance.

推荐答案

在按钮的主页面单击事件中,您可以将Page属性强制转换为界面,然后在其上调用Save。



In your master page click event for the button you can cast the Page property to the interface and then call Save on that.

protected void myButton_Click(object sender, EventArgs e)
        {
            ICanSave myPage = this.Page as ICanSave;
            myPage.Save();
        }







public interface ICanSave
    {
        void Save();
    }


这篇关于如何通过单击母版页按钮来调用内容页面方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆