Access Parent Page Property from User Control

Trying to access a property from the parent page on my user control.

Here's the start of my default.asp codebehind:

Partial Class _Default
     Inherits System.Web.UI.Page

     Private _selectedID As String = "74251BK3232"

     Public Property SelectedID() As String
               Return _selectedID 
          End Get
          Set(ByVal value As String)
               _selectedID = value
          End Set
     End Property

Here's the start of my user control codebehind:

Partial Class ctrlAddAttribute
    Inherits System.Web.UI.UserControl
     Dim selectedID As String = Me.Parent.Page.selectedID()

I'm getting the error "selectedID is not a member of System.Web.UI.Page"

Please adivse!


You could access the property when you cast the Page to your actual implementaion called _Default.

Dim selectedID As String = DirectCast(Me.Page,_Default).selectedID()

But that is not the purpose of a Usercontrol(reusability). Normally you would give the ID from the Controller(page) to the UserControl.

So define a property in the UserControl and set it from the page. On this way the UserControl would still work in other pages.

Need Your Help

JDBC URL is null?

spring hibernate jdbc spring-jdbc

Depending on my Spring Profile Hibernate should update (development) or validate (production) db schema. But I'm getting this exception:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.