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
Get
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.
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.