Setting the value of a Master page's control's property using a property of the Master page

Setting the value of a Master page's control's property using a property of the Master page

Post by Nathan Sok » Thu, 25 Feb 2010 08:24:25


I have a Master page that contains a custom property, defined as follows:


Public Property SelectedNavigationID() As String
Get
Return Me.leftnavNavigation.SelectedNavigationID
End Get
Set(ByVal value As String)
Me.leftnavNavigation.SelectedNavigationID = value
End Set
End Property


As you can see, this property is used to set the value of a property of one
of the Master page's Controls. I set the property from the Content page as
follows:


Private Sub Page_PreInit(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreInit
Me.Master.SelectedNavigationID = "menuConditionalValidator"
End Sub


The problem occurs in the Set method of the property defined in the Master
page; it tells me that Me.leftnavNavigation has a value of Nothing, which
obviously prevents me from setting the property. I know that I am missing
something simple, because this is almost exactly the same as a previous
version of the site I am recreating, which works perfectly. What could be
causing the problem? Any help would be appreciated. Thanks.
--
Nathan Sokalski
XXXX@XXXXX.COM
http://www.yqcomputer.com/
 
 
 

Setting the value of a Master page's control's property using a property of the Master page

Post by Alexey Smi » Thu, 25 Feb 2010 09:03:56


> Return Me.leftnavNavigation.SelectedNa>igationID
> gt;End Get
> Set(ByVa> value As String)
> Me.leftnavNavigation.Se>ectedNavigatio>ID = value
> gt;> End Set
> End Property
>
> As you can see, this property is used to set >he value of a property of one
> of the Master page's Controls. I set the pro>erty from t>e >ontent page as
> follows:
>
> Private Sub Page_PreInit(ByVa> sender As Object, ByVal e As
> System>EventArgs) Handles Me.PreInit
> Me.Master.SelectedNavigat>onID = "me>uC>nditionalValidator"
> End Sub
>
> The problem occurs in the Set method of >he property defined in the Master
> page; it tells me that Me.leftnavNaviga>ion has a value of Nothing, which
> obviously prevents me from setting the >roperty. I know that I am missing
> something simple, because this is alm>st exactly the same as a previous
> version of the site I am recreating, wh>ch works perfectly. What could be
> causing the problem? Any >elp w>uld be appreciated> Thanks.
> --
> Nathan Sokalski
> XXXX@XXXXX.COM ://www.nathansokalski.com/

Try to move the contentpage's code to Page_Load

 
 
 

Setting the value of a Master page's control's property using a property of the Master page

Post by Nathan Sok » Thu, 25 Feb 2010 12:06:30

That would not work, because properties of Controls in the Master page must
be set in the PreInit event.
--
Nathan Sokalski
XXXX@XXXXX.COM
http://www.yqcomputer.com/