473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

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
Apr 5 '06 #1
5 1935
Is "CategoriesByStoreUC.ascx" the id of the user control in the Master page
?
you need to use the id when using FindControl

"Paul" <Pa***********@TheCornerStore.com> wrote in message
news:V8***********@fe12.lga...
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

Apr 5 '06 #2
Yes it is, Thanks,

Paul
"Swanand Mokashi" <sw***********@swanandmokashi.com> wrote in message
news:ui**************@TK2MSFTNGP05.phx.gbl...
Is "CategoriesByStoreUC.ascx" the id of the user control in the Master
page ?
you need to use the id when using FindControl

"Paul" <Pa***********@TheCornerStore.com> wrote in message
news:V8***********@fe12.lga...
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


Apr 5 '06 #3
as in -- that fixed it ??
"Paul" <Pa***********@TheCornerStore.com> wrote in message
news:mo***********@fe12.lga...
Yes it is, Thanks,

Paul
"Swanand Mokashi" <sw***********@swanandmokashi.com> wrote in message
news:ui**************@TK2MSFTNGP05.phx.gbl...
Is "CategoriesByStoreUC.ascx" the id of the user control in the Master
page ?
you need to use the id when using FindControl

"Paul" <Pa***********@TheCornerStore.com> wrote in message
news:V8***********@fe12.lga...
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



Apr 5 '06 #4
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

"Swanand Mokashi" <sw***********@swanandmokashi.com> wrote in message
news:OB**************@TK2MSFTNGP04.phx.gbl...
as in -- that fixed it ??
"Paul" <Pa***********@TheCornerStore.com> wrote in message
news:mo***********@fe12.lga...
Yes it is, Thanks,

Paul
"Swanand Mokashi" <sw***********@swanandmokashi.com> wrote in message
news:ui**************@TK2MSFTNGP05.phx.gbl...
Is "CategoriesByStoreUC.ascx" the id of the user control in the Master
page ?
you need to use the id when using FindControl

"Paul" <Pa***********@TheCornerStore.com> wrote in message
news:V8***********@fe12.lga...
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



Apr 5 '06 #5
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("'Categori esByStoreUC1");

assuming your web control type is CategoriesByStoreUC and it should work

"Paul" <Pa***********@TheCornerStore.com> wrote in message
news:HU************@fe12.lga...
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

"Swanand Mokashi" <sw***********@swanandmokashi.com> wrote in message
news:OB**************@TK2MSFTNGP04.phx.gbl...
as in -- that fixed it ??
"Paul" <Pa***********@TheCornerStore.com> wrote in message
news:mo***********@fe12.lga...
Yes it is, Thanks,

Paul
"Swanand Mokashi" <sw***********@swanandmokashi.com> wrote in message
news:ui**************@TK2MSFTNGP05.phx.gbl...
Is "CategoriesByStoreUC.ascx" the id of the user control in the Master
page ?
you need to use the id when using FindControl

"Paul" <Pa***********@TheCornerStore.com> wrote in message
news:V8***********@fe12.lga...
>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
>
>



Apr 5 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve Franks | last post by:
I am trying to access strongly typed properties in a page's master page from the content page. I followed an article that describes how to do this, and it seems quite straight forward. However...
2
by: Alexander Widera | last post by:
Hi, the situation is the following: There is this masterpage: <%@ Master Language="C#" AutoEventWireup="true" CodeFile="mymaster.master.cs" Inherits="mymaster" %> <%@ Register...
5
by: RedHair | last post by:
I have a ASP.NET 2.0 web page which inherits a customized base page class and have a master page, their relation is as below Customized base page class --> web page --> master page How to...
4
by: RedHair | last post by:
I have a base page class A which inherits System.Web.UI.Page class then a aspx page B inherits class A and have a master page C. There is a property D (a string variable) in the master page C. ...
3
by: ivanpais | last post by:
Hi, I have a Web User Control, Lets say "Foo.ascx", that contains a button "btnFoo". I have a Master Page "Bar.master", that has a label "lblBar". This label is exposed by a public property...
4
by: Boris Yeltsin | last post by:
OK, on my Master Page I have a control: <a id="hypTabAccount" href="#" runat="server">Account</a> Now, in the code-behind (Root.master.vb) I can refer to it simply thus: ...
1
by: pierre | last post by:
Hi, I have a DataList inside a UserControl, which I use on a MasterPage. My ContentPage lists items which a user can add to his/her shopping basket. Can someone PLEASE let me know how I can...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
3
by: eselk2003 | last post by:
I'm just starting out with VWD 2008, and new to ASP .NET. I have a master page which displays one record for an Access database based on an ID number in the query string. Then I have a content...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.