Calling label or other tools in toolbox from master page to use in other pages in asp.net using c#

This article show how to call label or other tools in toolbox from master page to use in other pages in asp.net using C#. In this example i want to use label from master page and called it in other page.

Code Design:
Master page:    

<asp:ContentPlaceHolder ID="ulogin" runat="server">
   <asp:Label ID="LblUserLogin" runat="server"></asp:Label>
</asp:ContentPlaceHolder>

Code Behind:
  other page:

// Declare ContentPlaceHolder
ContentPlaceHolder mpContentPlaceHolder;
// Declare Label
Label userlogin;
/* Assign ContentPlaceHolder in Master page to new declared ContentPlaceHolder */
mpContentPlaceHolder = (ContentPlaceHolder)Master.FindControl("ulogin");
// Assign Label in ContentPlaceHolder of Masterpage to new declared label
userlogin = (Label)mpContentPlaceHolder.FindControl("LblUserLogin");
// Using call label from master page
userlogin.Text = "You are login as : " + Session["Username"].ToString();


Hope this post is helpful for you.
Calling label or other tools in toolbox from master page to use in other pages in asp.net using c# Calling label or other tools in toolbox from master page to use in other pages in asp.net using c# Reviewed by BeiLover on 12:36 PM Rating: 5

No comments:

Powered by Blogger.