Page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserControlMainPage.aspx.cs" Inherits="EEWebModelApp.UserControlMainPage" %>
<%@ Register src="MyUserControl.ascx" tagname="MyUserControl" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="MyLabel" runat="server"></asp:Label>
<uc1:MyUserControl ID="MyUserControl1" runat="server" />
</div>
</form>
</body>
</html>
Page Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace EEWebModelApp
{
public partial class UserControlMainPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string LabelText
{
set
{
MyLabel.Text = value;
}
}
}
}
Control
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyUserControl.ascx.cs" Inherits="EEWebModelApp.MyUserControl" %>
<asp:Label ID="MyLabel" runat="server"></asp:Label><br /><br />
<asp:Button ID="MyButton" runat="server" Text="Click Me"
onclick="MyButton_Click" />
Control Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace EEWebModelApp
{
public partial class MyUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void MyButton_Click(object sender, EventArgs e)
{
MyLabel.Text = "<p>This is some text in the user control</p>";
((UserControlMainPage)Page).LabelText = "<p>This is some text in the page</p>";
}
}
}