Monday, January 23, 2012

Access Master Page Property and Master Page control in .aspx Form.


First Create a Master Page..

 <form id="form1" runat="server">
    <div>
    <asp:Label ID="lblname" Text="Hello" runat="server" BackColor="#FF6600"
            Font-Bold="True" ForeColor="#0066FF"></asp:Label>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
      
        </asp:ContentPlaceHolder>
    </div>
    </form>

-> Create Property in .master.cs Page
    private string _Name;
    public string Name
    {
        get { return _Name; }
        set { _Name = value; }

    }

Now Create a Default.aspx Page...
Add One Line
<%@ MasterType VirtualPath="~/Site1.Master" %>

Now Add a Code in Default.aspx.cs Page in Load Event of Page

 Master.Name = "This is a Demo Of Accessing Master Page Control";

and Now you can use this Property.....

Now accessing the Control of Master Page..

 Label lbl = (Label)Master.FindControl("lblName");
 lbl.Text = "This is a Demo Of Accessing Master Page Control";


->This all discussion is about how to use master page control or Property of it..

0 comments:

Post a Comment