In this post i will show how to assign values for labels in master page from content page.
I have 2 labels lblfirstname and lbllastname.
Need to assign value for this labels from content page.
Master page html
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="height:200px; width:600px;">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:Label ID="lblmsg" runat="server" Text="First Name and Last Name values are assigned from content page:"></asp:Label>
<br />
<asp:Label ID="lblfirstname" runat="server" Text=""></asp:Label>
<asp:Label ID="lbllastname" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
Content Page cs code
protected void Page_Load(object sender, EventArgs e)
{
// To set the lable value to maste page
Label lblname1 = (Label)Master.FindControl("lblfirstname");
lblname1.Text = "Manoj ";
Label lblname2 = (Label)Master.FindControl("lbllastname");
lblname2.Text = "Kumar";
}
Result
No comments:
Post a Comment