473,659 Members | 2,920 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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???>.sectio nID
Case "home"
sectionHeaderLa bel.Text = "Welcome section"
Case "about"
sectionHeaderLa bel.Text = "Another section"
Case Else
sectionHeaderLa bel.Text = "Error"
End Select

End Sub

--
_____
DC G
Jul 21 '05 #1
3 1570
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
programmaticall y 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******@visio ntechnology.net > wrote in message
news:uB******** ******@tk2msftn gp13.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???>.sectio nID
Case "home"
sectionHeaderLa bel.Text = "Welcome section"
Case "about"
sectionHeaderLa bel.Text = "Another section"
Case Else
sectionHeaderLa bel.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(se ctionID As String)'."

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

myPage.ascx has:
--------------------------
Public Sub theSectionID(By Val sectionID As String)
Select Case sectionID
Case "home"
sectionHeaderLa bel.Text = "Welcome"
Case "about"
sectionHeaderLa bel.Text = "About"
Case Else
sectionHeaderLa bel.Text = "Error"
End Select
End Sub
"Marina" <so*****@nospam .com> wrote in message
news:uv******** ******@tk2msftn gp13.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
programmaticall y 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******@visio ntechnology.net > wrote in message
news:uB******** ******@tk2msftn gp13.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???>.sectio nID
Case "home"
sectionHeaderLa bel.Text = "Welcome section"
Case "about"
sectionHeaderLa bel.Text = "Another section"
Case Else
sectionHeaderLa bel.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******@visio ntechnology.net > wrote in message
news:uB******** ******@tk2msftn gp13.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???>.sectio nID
Case "home"
sectionHeaderLa bel.Text = "Welcome section"
Case "about"
sectionHeaderLa bel.Text = "Another section"
Case Else
sectionHeaderLa bel.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
11276
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" Src="WebControls/Header.ascx" %> The web user control contains the following server controls
3
1026
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 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...
4
3385
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 something like: this.Parent.FindControl("pnlExample").Visible = true; or if this is to be referenced with some frequency, store it to a field in the control then reference that. Is there a better way?
4
2433
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 server-side-include directive: <!-- include virtual="../../foobar.aspx"--> c)When the .stm file is rendered: The .aspx file is included, but it doesn't look like the ASP.NET engine is processing the page, because I see the raw
3
3853
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 hyperlink control and you assign the navigateurl property = "../#anchor" whereby you want to add this # reference to the current url the url ends up with the #anchor twice.
3
1723
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 attribute atop the .aspx page. This works fine, but this attribute is not recognized in controls. Thanks ~PJ
2
1646
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 MyUtils { public partial class SomeUserControl : System.Web.UI.UserControl { ... }
21
5093
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 form, the code errors out at the 2nd line. The error number is 13 and the description is "Type mismatch". Both controls are memo fields. I suspect that "Screen.ActiveControl.Parent" is not referencing the form as intended. Thanks for any help,...
2
1476
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 do I go about setting the properties of the controls within mycontrol.ascx directly from class1 Ideally what i'd like to do is various control property settings in class1
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8747
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6179
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.