Hi,
Sometime we need to work with ContentPlaceHolder that is present in our master page, and we have to edit that ContentPlaceHolder by one user control .
So problem is that "how i can access master page content in my usercontrol ? " :-( .
When i had this situation i was full tension but finally i got solution and it was easy.
But there is some points which i should share with you. Always find parent content place holder then go to child like hierarchy. So you will not get error "Null reffrence".
Suppose you have a one ContenPlaceHolder that has ID "footerPrintHide" . So you can find that ContentPlaceHolder like this
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Dim xx As ContentPlaceHolder =
CType(Me.Page.Master.FindControl("footerPrintHide"), ContentPlaceHolder)
xx.Visible = False
But this should be parent ContentPlaceholder mean there is no other contetplaceholder holding this one
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Some time we do required to find control inside the ContentPlaceHolder. So for this first we will find ContentPlaceHolder then using that reference we can find child control .
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Dim xx As ContentPlaceHolder =
CType(Me.Page.Master.FindControl("footerPrintHide"), ContentPlaceHolder)
xx.FindControl("printHideDiv").Visible = False
And this will not give you "null reference" error.
Thanks and regards
Shailendra singh
Sometime we need to work with ContentPlaceHolder that is present in our master page, and we have to edit that ContentPlaceHolder by one user control .
So problem is that "how i can access master page content in my usercontrol ? " :-( .
When i had this situation i was full tension but finally i got solution and it was easy.
But there is some points which i should share with you. Always find parent content place holder then go to child like hierarchy. So you will not get error "Null reffrence".
Suppose you have a one ContenPlaceHolder that has ID "footerPrintHide" . So you can find that ContentPlaceHolder like this
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Dim xx As ContentPlaceHolder =
CType(Me.Page.Master.FindControl("footerPrintHide"), ContentPlaceHolder)
xx.Visible = False
But this should be parent ContentPlaceholder mean there is no other contetplaceholder holding this one
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Some time we do required to find control inside the ContentPlaceHolder. So for this first we will find ContentPlaceHolder then using that reference we can find child control .
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Dim xx As ContentPlaceHolder =
CType(Me.Page.Master.FindControl("footerPrintHide"), ContentPlaceHolder)
xx.FindControl("printHideDiv").Visible = False
And this will not give you "null reference" error.
Thanks and regards
Shailendra singh
No comments:
Post a Comment