473,406 Members | 2,769 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,406 software developers and data experts.

referencing the page from a control

I have an myPage.aspx with a myPage.ascx user control. The user control is
the main header of the page. I have some conditional case code in the user
control that I use which depends on a public variable "sectionID" set int he
myPage.aspx's code-behind. How can I reference that variable in my control
dynamically? I can hard card in the name of the myPage.aspx.vb class but
that doesn't help me if the control is used within many different pages.

---------------------------------------------------
In my myPage.aspx.vb, I have:

Public sectionID As String = "home"


---------------------------------------------------
In my myPage.ascx, I have:
Public Sub theSectionID()

Select Case <WHAT GOES HERE???>.sectionID
Case "home"
sectionHeaderLabel.Text = "Welcome section"
Case "about"
sectionHeaderLabel.Text = "Another section"
Case Else
sectionHeaderLabel.Text = "Error"
End Select

End Sub

--
_____
DC G
Jul 21 '05 #1
3 1553
You would need to cast the Page property of the user control, to the type of
your Page (whatever that name is). This means you would need a reference to
the assembly that contains your page in the project for the user control (if
they are separate project0> Once you have a variable of the right type
pointing to the page, the sectionID variable should be available since it is
public.

Another way to do this, is to use reflection on the Page property of the
user control, look for a member called 'sectionID', and then
programmatically retrieve its value. This is kind of messy.

The best solution, would probably to expose a method or property on your
user control, that the page can call to pass in the sectionID. The user
control would store it for later access.

Either that, or have that be a parameter to theSectionID method, if the page
is doing the calling.
"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:uB**************@tk2msftngp13.phx.gbl...
I have an myPage.aspx with a myPage.ascx user control. The user control is the main header of the page. I have some conditional case code in the user control that I use which depends on a public variable "sectionID" set int he myPage.aspx's code-behind. How can I reference that variable in my control dynamically? I can hard card in the name of the myPage.aspx.vb class but
that doesn't help me if the control is used within many different pages.

---------------------------------------------------
In my myPage.aspx.vb, I have:

Public sectionID As String = "home"


---------------------------------------------------
In my myPage.ascx, I have:
Public Sub theSectionID()

Select Case <WHAT GOES HERE???>.sectionID
Case "home"
sectionHeaderLabel.Text = "Welcome section"
Case "about"
sectionHeaderLabel.Text = "Another section"
Case Else
sectionHeaderLabel.Text = "Error"
End Select

End Sub

--
_____
DC G

Jul 21 '05 #2
I'm trying to expose a method on the user control and pass in the sectionID.
It's not working and I get error: "Argument not specified for parameter
'sectionID' of 'Public Sub theSectionID(sectionID As String)'."

What I have is:
myPage.aspx has:
--------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim sectionID As String
sectionID = "home"
mainHeader1.theSectionID(sectionID)
End Sub

myPage.ascx has:
--------------------------
Public Sub theSectionID(ByVal sectionID As String)
Select Case sectionID
Case "home"
sectionHeaderLabel.Text = "Welcome"
Case "about"
sectionHeaderLabel.Text = "About"
Case Else
sectionHeaderLabel.Text = "Error"
End Select
End Sub
"Marina" <so*****@nospam.com> wrote in message
news:uv**************@tk2msftngp13.phx.gbl...
You would need to cast the Page property of the user control, to the type of your Page (whatever that name is). This means you would need a reference to the assembly that contains your page in the project for the user control (if they are separate project0> Once you have a variable of the right type
pointing to the page, the sectionID variable should be available since it is public.

Another way to do this, is to use reflection on the Page property of the
user control, look for a member called 'sectionID', and then
programmatically retrieve its value. This is kind of messy.

The best solution, would probably to expose a method or property on your
user control, that the page can call to pass in the sectionID. The user
control would store it for later access.

Either that, or have that be a parameter to theSectionID method, if the page is doing the calling.
"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:uB**************@tk2msftngp13.phx.gbl...
I have an myPage.aspx with a myPage.ascx user control. The user control is
the main header of the page. I have some conditional case code in the

user
control that I use which depends on a public variable "sectionID" set int he
myPage.aspx's code-behind. How can I reference that variable in my

control
dynamically? I can hard card in the name of the myPage.aspx.vb class

but that doesn't help me if the control is used within many different pages.

---------------------------------------------------
In my myPage.aspx.vb, I have:

Public sectionID As String = "home"


---------------------------------------------------
In my myPage.ascx, I have:
Public Sub theSectionID()

Select Case <WHAT GOES HERE???>.sectionID
Case "home"
sectionHeaderLabel.Text = "Welcome section"
Case "about"
sectionHeaderLabel.Text = "Another section"
Case Else
sectionHeaderLabel.Text = "Error"
End Select

End Sub

--
_____
DC G


Jul 21 '05 #3
You can have a public function or sub in myPage.ascx which is called during
the page_load event of the hosting page. Pass it the value there, or if you
want it to have more access, pass it the page.

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:uB**************@tk2msftngp13.phx.gbl...
I have an myPage.aspx with a myPage.ascx user control. The user control is the main header of the page. I have some conditional case code in the user control that I use which depends on a public variable "sectionID" set int he myPage.aspx's code-behind. How can I reference that variable in my control dynamically? I can hard card in the name of the myPage.aspx.vb class but
that doesn't help me if the control is used within many different pages.

---------------------------------------------------
In my myPage.aspx.vb, I have:

Public sectionID As String = "home"


---------------------------------------------------
In my myPage.ascx, I have:
Public Sub theSectionID()

Select Case <WHAT GOES HERE???>.sectionID
Case "home"
sectionHeaderLabel.Text = "Welcome section"
Case "about"
sectionHeaderLabel.Text = "Another section"
Case Else
sectionHeaderLabel.Text = "Error"
End Select

End Sub

--
_____
DC G

Jul 21 '05 #4

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

Similar topics

6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
3
by: DC Gringo | last post by:
I have an myPage.aspx with a myPage.ascx user control. The user control is the main header of the page. I have some conditional case code in the user control that I use which depends on a public...
4
by: John Spiegel | last post by:
Hi all (again), Next question: I have a Web user control contained in a page. How would I go about referencing the other objects in the page from within the control? One way seems to use...
4
by: TWEB | last post by:
I think I may have an IIS / ASP.Net Configuration issue that I need some guidance with resolving. Here's the problem: a) I have a .stm file. b) I referenc a .aspx file on this .stm file using a...
3
by: gary | last post by:
Hi, I am trying to reference an anchor in a user control with a url. This worked in 1.1 but no longer works in 2.0. The ascx control is located in a "/include" folder If you have a...
3
by: PJ | last post by:
I am trying to get reference to a Master page from a web user control. However, I cannot seem to even access the type. I have been referencing the master page in forms by declaring the master...
2
by: Alex Maghen | last post by:
I want to create a utility function that will seach the current page for one of my UserControls by it's type. So, let's say that I have a UserControl whose class I defined as follows: namespace...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
2
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post by:
Hi all I have a user control - mycontrol.ascx with various controls within it. mycontrol.ascx is utilised in myPage.aspx I have a class (class1) to carry out various functions, subs etc. How...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.