Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 15-Nov-14 8:40am
v2
Comments
Dhaneshmon 15-Nov-14 23:31pm    
I was creating a web application. So in my app there is a Master page. My plan is put save and cancel button only in master page. so I have created on interface(void Save(), void Cancel()) and all my content page will inherit this interface. Michael Ulmann gave me a solution to implement the same. :)
Michael Ulmann 16-Nov-14 1:14am    
Just bear in mind that best practise would be to check for null before using the interface casted object.
Dhaneshmon 16-Nov-14 13:00pm    
Sure. Thanks a lot for your assist.

1 solution

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

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


C#
public interface ICanSave
    {
        void Save();
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900