How to access a UserControl in a Master apge from a content page

P

Paul

I have a MasterPage that has on it several UserControls (*ascx files). I
wish to control the visibility of the controls on the content pages
according to some parameter (for example on a user control that depends on a
param StoreID, for the UserControl to be visible only if StoreID is in the
query string.)
How can I access a UserControl in a MasterPage from a Content page?

I tried this, and variations thereof, but get errors:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Dim StoreID As Integer = Convert.ToInt32(Request.QueryString("StoreId"))

If Not StoreID.ToString Is Nothing Then

'Master.FindControl("ProductsByStoreAndCategoryUC.ascx").Visible = True

Dim myLocalMasterPage As MasterPage = Me.Master

Dim myControl As UserControl =
myLocalMasterPage.FindControl("CategoriesByStoreUC.ascx")

myControl.Visible = True

End If

End Sub

------------------------------------------

Thank you for any help,



Paul
 
S

Swanand Mokashi

Is "CategoriesByStoreUC.ascx" the id of the user control in the Master page
?
you need to use the id when using FindControl
 
P

Paul

Yes it is, Thanks,

Paul


Swanand Mokashi said:
Is "CategoriesByStoreUC.ascx" the id of the user control in the Master
page ?
you need to use the id when using FindControl
 
P

Paul

No, given that the control on the Master page is called
"CategoriesByStoreUC.ascx", how can I access the visibility of this control
from a Content Page, say the StoresPage.aspx?

Thanks

Paul
 
S

Swanand Mokashi

assigning such an Id is not throwing an "'CategoriesByStoreUC.ascx' is not a
valid identifier." errror ??? -- it should !!
Change the id to not use the .ascx and you can say call it
"CategoriesByStoreUC1" and then use the following in your aspx page :

CategoriesByStoreUCaddComments =
(CategoriesByStoreUC)Master.FindControl("'CategoriesByStoreUC1");

assuming your web control type is CategoriesByStoreUC and it should work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top