Button events on the master page

Source: Internet
Author: User

To solve this problem, first understand one thing. masterpage is just a container that will load a lot of web pages, where the Div is placed, and try to let masterpage know. For example, the P1.aspx page contains a Div id of Div1, and P2.aspx also has a Div id of Div1. Masterpage does not know whether the Div1. Div of the page you want to display only needs to be displayed or not. No matter who controls it, it can be controlled by the page or masterpage.
Therefore, you can write an interface with a method and a parameter:
ISetable
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;

/// <Summary>
/// Summary description for ISetable
/// </Summary>
Namespace Insus. NET
{
Public interface ISetable
{
Void Setting (bool show );
}
}

 
If the Div of P1 needs to be controlled, implement this interface in P1.aspx. cs. Of course, if P2.aspx is used, it is the actual interface of P2.aspx. cs.
View Code
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using Insus. NET;

Public partial class P1: System. Web. UI. Page, ISetable
{
Protected void Page_Load (object sender, EventArgs e)
{

}

Public void Setting (bool show)
{
This. Div1.Visible = show;
}
}

 
Finally, you can determine who controls it. If it is masterpage or page, write it in the button Click event of the container:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using Insus. NET;

Public partial class MasterPage: System. Web. UI. MasterPage
{
Protected void Page_Load (object sender, EventArgs e)
{

}

Protected void button#click (object sender, EventArgs e)
{
ISetable d = (ISetable) this. Page;
D. Setting (true );
}
} C: \ Documents and Settings \ Administrator \ Local Settings \ Temporary Internet Files \ Content. IE5 \ 0UWRZ0I1 \ expandedblockstart1_12.16.gif


 

Demo: http://www.bkjia.com/uploadfile/2012/0310/20120310083824499.rar
 

 

The following content is added on: 10:

The reconstruction is as follows, and the two buttons are integrated into one. effect :.



 

Click Event:
View Code
Protected void button#click (object sender, EventArgs e)
{
Button btn = (Button) sender;
ISetable d = (ISetable) this. Page;

Switch (btn. Text)
{
Case "open ":
Btn. Text = "off ";
D. Setting (true );
Break;
Case "off ":
Btn. Text = "open ";
D. Setting (false );
Break;
}
}
 

From Insus. NET

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.