You cannot get the property of parent page but you can get the Controls value like this. I am setting the property value in HiddenField and finding the HiddenField value in UserControl PageLoad event.
HTML:
ASPX:
<form id="form1" runat="server">
<div>
<uc:TextBox runat="server"></uc:TextBox>
<asp:HiddenField ID="hdName" runat="server" />
</div>
</form>
ASPX C#:
public string Name
{
set
{
this.hdName.Value = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Name = "Shaikh Azimuddin";
}
}
ASCX:
<asp:TextBox ID="txtName" runat="server" />
<asp:Button Text="Submit" runat="server"/>
ASCX C#:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.txtName.Text = ((this.Parent.Page).FindControl("hdName") as HiddenField).Value;
}
}
Register UserControl
<%@ Register Src="~/UserControl/UC_TextBox.ascx" TagName="TextBox" TagPrefix="uc" %>
Thank You.