Change the master page when clicking a button in master

asp.net, c#, c#-4.0, master-pages

Solution

- In the Master Page use input type submit button

<`input` type="`submit`" name="`btnGreen`" value="Green" />

<`input` type="`submit`" name="`btnBlue`" value="Blue" />

2.Then from the code behind you can check the name of the button clicked, in the Request object in the Page_PreInit event

public partial class Default : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Request["btnGreen"] != null)
        {
            Page.MasterPageFile = "/Green.Master";
        }
        else if (Request["btnBlue"] != null)
        {
            Page.MasterPageFile = "/Blue.Master";
        }
    }

}

Problem

I am having three master pages like `Master-Green, Master-Bule, Master-Red`. In each master page having three buttons named as `green, blue and red`. Now my `default master is green`, It's assigned a page `Default.aspx`. At this time three button also display on the top. How to make so clicking "blue" button means the Master-Blue shold be master page for the current page?

Original source