Thursday, August 13, 2009

Handle Master page Click Event on Content Page

In ASP.net2.5 there a new concept knowns as Master Page , with the help of that you can
customize you'r repeteative work. Create a one Master page and use that page on all the other pages. Its really very good tech to crear your coding and clear your logic also.

now sometime we have a LinkButton define on Master page which can be work as a "Link to the Customer information " and this can be change depend on customer role. and that LinkButton action we want in the Contenet page.

Supoose we have LinkButton call "linkFromMasterPage" on Master Page. Here is small code which can helps you to do same .


Public LinkButton linkFromMasterPage(){

Get {

Return linkFromMasterPage;



Now next Process is reference the Master Page as a casted object in the Content page.
here CusMasterPg is a Class of Maste Page.

CusMasterPg cm = ((CusMasterPg) (Master));

Now you can easily access the all the methods, public properties of Master page class.
so next stpe is handle the button Event on your content page

protected void Page_Load(object sender, EventArgs e)
If (!(IsNothing(cm))) {

cm.linkFromMasterPage.Click += New EventHandler(linkFromMasterPage_Click);


next thing is define actual method handle on your page.

Protected void linkFromMasterPage_Click(Object sender, System.EventArgs e){

// write Perform Business Logic Here

thats all , you can do same thing for User Controls also for Handle Master page Click Event on Content Page.

No comments:

Post a Comment