473,385 Members | 1,597 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,385 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 1551
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.