How to handled Button Click Event when button will be on Master Page
B Sahoo Posted On : 18/02/2012
About Author
Biswaranjan Sahoo have good working and teching experience in Microsoft technology.

How to handled Button Click Event when button will be on Master Page

Step-1: First u will create a Event of CommandEventHandler Delegate type In master .cs

File. public partial class SiteMaster : System.Web.UI.MasterPage { public event CommandEventHandler addbutton; protected void btnsubmit_Click(object sender, EventArgs e) { addbutton(this, new CommandEventArgs(btnsubmit.CommandName.ToString(), e)); } protected void Page_Load(object sender, EventArgs e) { } } //This is delegate optional public delegate void CommandEventHandler( Object sender, CommandEventArgs e )

Step-2. In content page add MasterType directive content page as bellow.

<%@ MasterType VirtualPath="~/Site.master" %>

Step-3. In content page cs file write following code

TextBox txtbox; protected void Page_Init(object sender, EventArgs e) { // Wire up the event (Master_addbutton) to the event handler (MoodChangedFromMasterPage) Master.addbutton +=new CommandEventHandler(Master_addbutton); } void Master_addbutton(object sender, CommandEventArgs e) { txtbox = (TextBox)Master.FindControl("txtname"); string name = txtbox.Text; Label1.Text = name; } protected void Page_Load(object sender, EventArgs e) { }

Post your Suggetion or Comment
Name :
Email Address :
Comment :