I'm having trouble to access a Parent's property in User Control. I don't know how to access the parent. I saw the example below and tried it:

CType(Me.Page, Search).Prop = VALUE

and the Parent page is called Search.aspx

Partial Class Search

But then I get en error Type 'Search' is not defined.

I have also tried:

Dim p as Page=Me.Parent.Page
p.Prop 'doesn't work

But I can't access the Property in this way either

Please help

I presume that the parent of usercontrol is a Panel then your code in usercontrol might be,


Thanks for the answer, but no, the User Control is not placed in a panel. And how would I be able to access the panel in the Parent when I even can't access the Parent Page.


I found the solution I added

<%@ Reference Page="~/Search.aspx" %>

in the User Control's ascx file and then I could access the Parent's
Property with

Dim parentPage As Search = CType(Page, search)

Thanks for the help

:'( Hi again

No, it didn't work when I tried to run the website. Than it gave me the errors
1. The user control is not declared in the parent page
2. The user contol has a circular reference

Please help me


Firstly add a code-file into your project which must be a subclass of System.Web.UI.Page class.

MyPage.vb (in app_code folder)

Public MustInherit Class MyPage
    Inherits System.Web.UI.Page
    Public MustOverride Property MyText() As String
End Class

Code & markup of Usercontrol.


<%@ Control Language="VB" ClassName="TestControl" %>

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim method As MyPage = CType(Me.Page, MyPage)
        method.MyText = "Hello"
    End Sub

Webform - Make sure that the .aspx page directive includes Inherits="MyPage" attribute.


<%@ Page Language="VB" Inherits="MyPage" %>

<%@ Register src="TestControl.ascx" tagname="TestControl" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    Public Overrides Property MyText() As String
            Return TextBox1.Text
        End Get
        Set(ByVal value As String)
            TextBox1.Text = value
        End Set
    End Property

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
        <uc1:TestControl ID="TestControl1" runat="server" />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


Thank's for the answer, but how will I be able to use the other code in the Parent Page if I inherit the Parent to MyPage.

I'am a new to ASP.Net. Sorry


use this funtion to find the control

Private Shared Function FindControlRecursive(ByVal Root As Control, ByVal Id As String) As Control
        If Root.ID = Id Then
            Return Root
        End If

        For Each Ctl As Control In Root.Controls
            Dim FoundCtl As Control = FindControlRecursive(Ctl, Id)
            If FoundCtl IsNot Nothing Then
                Return FoundCtl
            End If
        Return Nothing
    End Function

Find the control with the next statement

Dim lbl As Label = FindControlRecursive(Page.Master, "yourControlID")