Development Desk

Just another WordPress.com site

ASP.NET Master Page Controls, Contents or methods make available to all Derived pages.

Referencing Custom Master Page technique could be very help in the situation in which you want to access some master page to its Content pages e.g. User open a website and He/She gets Login to website now you needs user ID on every derived page to use or fetch some information from the database. It can be done in few easy steps

1. In Master page (Code behind file) make public property

public String UserID

{

get{ return (String)Session[“UserIdNumber”]; }

set{ Session[“UserIdNumber”] = value; }

}

2. After all @Page Directives properties Add @ MasterType declaration

<%@ Page Language = “C#” MasterPageFile = “~/Interface.master” …. %>

<@ MasterType VirtualPath = “~/Interface.master” %>

3. now simply Reference the Master page Property from the Content Page

e.g.

String userId = Master.UserID;

it was the overall procedure to use this technique to set one property and accessible for all content pages.

to access control in child page FindControl method can be used

this code should be in Page_Load method and master page control must be public

Label lblUserID = (Label)Master.FindControl(“lblLoginUserID”);

lblUserID.Text = “Any value :-)”;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: