473,657 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem accessing property value in User Control

I have a property in a user control that I am setting:

Private strPageName as String
Public Property PageName() as String
Get
Return strPageName
End Get
Set(byVal Value as String)
strPageName = Value
End Set
End Property

So why can't I access strPageName in any of my functions? I am setting this
property from the parent page that the user control is in. It is always
Nothing by the time I get to my functions even though I can see it come in
initially.

Thanks in advance!
May 4 '06 #1
6 1515
You need to show us when and how you are calling these functions. Also,
exactly when you are setting the property.
"David Hearn" <Da*********@sh awinc.com> wrote in message
news:uV******** *****@TK2MSFTNG P04.phx.gbl...
I have a property in a user control that I am setting:

Private strPageName as String
Public Property PageName() as String
Get
Return strPageName
End Get
Set(byVal Value as String)
strPageName = Value
End Set
End Property

So why can't I access strPageName in any of my functions? I am setting
this property from the parent page that the user control is in. It is
always Nothing by the time I get to my functions even though I can see it
come in initially.

Thanks in advance!

May 4 '06 #2
Setting the property from the Page_Load event of the parent page.

Parent Page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim objHeader As New Header
objHeader.PageN ame = "Stock Check"
objHeader = Nothing
End If
End Sub

Public property is listed below in original message. Then I am am calling
the function in the user controls Page_PreRender event per a suggestion from
someone else. SetHeaderInfo is the name of the function and trying to pass
strPageName as the variable that is set in the property:

Private Sub Page_PreRender( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.PreRende r
SetHeaderInfo(s trPageName)
End Sub
Thanks!

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:Ot******** ********@TK2MSF TNGP03.phx.gbl. ..
You need to show us when and how you are calling these functions. Also,
exactly when you are setting the property.
"David Hearn" <Da*********@sh awinc.com> wrote in message
news:uV******** *****@TK2MSFTNG P04.phx.gbl...
I have a property in a user control that I am setting:

Private strPageName as String
Public Property PageName() as String
Get
Return strPageName
End Get
Set(byVal Value as String)
strPageName = Value
End Set
End Property

So why can't I access strPageName in any of my functions? I am setting
this property from the parent page that the user control is in. It is
always Nothing by the time I get to my functions even though I can see it
come in initially.

Thanks in advance!


May 4 '06 #3
When would you be calling this method?

You are creating the object, setting a property, then setting the object
pointer to nothing - effectively meaning there are no more references to
this object, so nothing ever could call any methods on it. The object will
be garbage collected when the GC runs.

So there is no way you are calling any methods on the object. The object
never gets added to the page. You create it, set a property, then that's it.
Nothing else ever happens to it.

"David Hearn" <Da*********@sh awinc.com> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Setting the property from the Page_Load event of the parent page.

Parent Page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim objHeader As New Header
objHeader.PageN ame = "Stock Check"
objHeader = Nothing
End If
End Sub

Public property is listed below in original message. Then I am am calling
the function in the user controls Page_PreRender event per a suggestion
from someone else. SetHeaderInfo is the name of the function and trying to
pass strPageName as the variable that is set in the property:

Private Sub Page_PreRender( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.PreRende r
SetHeaderInfo(s trPageName)
End Sub
Thanks!

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:Ot******** ********@TK2MSF TNGP03.phx.gbl. ..
You need to show us when and how you are calling these functions. Also,
exactly when you are setting the property.
"David Hearn" <Da*********@sh awinc.com> wrote in message
news:uV******** *****@TK2MSFTNG P04.phx.gbl...
I have a property in a user control that I am setting:

Private strPageName as String
Public Property PageName() as String
Get
Return strPageName
End Get
Set(byVal Value as String)
strPageName = Value
End Set
End Property

So why can't I access strPageName in any of my functions? I am setting
this property from the parent page that the user control is in. It is
always Nothing by the time I get to my functions even though I can see
it come in initially.

Thanks in advance!



May 4 '06 #4
Marina,

I took the line out that sets objHeader to nothing to try it but my variable
is still coming out as nothing by the time the function gets called.

Thanks again!

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
When would you be calling this method?

You are creating the object, setting a property, then setting the object
pointer to nothing - effectively meaning there are no more references to
this object, so nothing ever could call any methods on it. The object will
be garbage collected when the GC runs.

So there is no way you are calling any methods on the object. The object
never gets added to the page. You create it, set a property, then that's
it. Nothing else ever happens to it.

"David Hearn" <Da*********@sh awinc.com> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Setting the property from the Page_Load event of the parent page.

Parent Page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim objHeader As New Header
objHeader.PageN ame = "Stock Check"
objHeader = Nothing
End If
End Sub

Public property is listed below in original message. Then I am am calling
the function in the user controls Page_PreRender event per a suggestion
from someone else. SetHeaderInfo is the name of the function and trying
to pass strPageName as the variable that is set in the property:

Private Sub Page_PreRender( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.PreRende r
SetHeaderInfo(s trPageName)
End Sub
Thanks!

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:Ot******** ********@TK2MSF TNGP03.phx.gbl. ..
You need to show us when and how you are calling these functions. Also,
exactly when you are setting the property.
"David Hearn" <Da*********@sh awinc.com> wrote in message
news:uV******** *****@TK2MSFTNG P04.phx.gbl...
I have a property in a user control that I am setting:

Private strPageName as String
Public Property PageName() as String
Get
Return strPageName
End Get
Set(byVal Value as String)
strPageName = Value
End Set
End Property

So why can't I access strPageName in any of my functions? I am setting
this property from the parent page that the user control is in. It is
always Nothing by the time I get to my functions even though I can see
it come in initially.

Thanks in advance!



May 4 '06 #5
Setting it to nothing doesn't really do anything, since it is a local
variable. As soon as the if block is done, the variable is out of scope,
and nothing anywhere can ever reference it again.

There is no possible way you are calling any methods on this object, because
as soon as the IF block is done, it can no longer be reference in any way.

"David Hearn" <Da*********@sh awinc.com> wrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Marina,

I took the line out that sets objHeader to nothing to try it but my
variable is still coming out as nothing by the time the function gets
called.

Thanks again!

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
When would you be calling this method?

You are creating the object, setting a property, then setting the object
pointer to nothing - effectively meaning there are no more references to
this object, so nothing ever could call any methods on it. The object
will be garbage collected when the GC runs.

So there is no way you are calling any methods on the object. The object
never gets added to the page. You create it, set a property, then that's
it. Nothing else ever happens to it.

"David Hearn" <Da*********@sh awinc.com> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Setting the property from the Page_Load event of the parent page.

Parent Page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim objHeader As New Header
objHeader.PageN ame = "Stock Check"
objHeader = Nothing
End If
End Sub

Public property is listed below in original message. Then I am am
calling the function in the user controls Page_PreRender event per a
suggestion from someone else. SetHeaderInfo is the name of the function
and trying to pass strPageName as the variable that is set in the
property:

Private Sub Page_PreRender( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.PreRende r
SetHeaderInfo(s trPageName)
End Sub
Thanks!

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:Ot******** ********@TK2MSF TNGP03.phx.gbl. ..
You need to show us when and how you are calling these functions. Also,
exactly when you are setting the property.
"David Hearn" <Da*********@sh awinc.com> wrote in message
news:uV******** *****@TK2MSFTNG P04.phx.gbl...
>I have a property in a user control that I am setting:
>
> Private strPageName as String
> Public Property PageName() as String
> Get
> Return strPageName
> End Get
> Set(byVal Value as String)
> strPageName = Value
> End Set
> End Property
>
> So why can't I access strPageName in any of my functions? I am setting
> this property from the parent page that the user control is in. It is
> always Nothing by the time I get to my functions even though I can see
> it come in initially.
>
> Thanks in advance!
>



May 4 '06 #6
Marina,

I got it working per some of Patrice's advice in the post above. Thanks for
your help!
"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Setting it to nothing doesn't really do anything, since it is a local
variable. As soon as the if block is done, the variable is out of scope,
and nothing anywhere can ever reference it again.

There is no possible way you are calling any methods on this object,
because as soon as the IF block is done, it can no longer be reference in
any way.

"David Hearn" <Da*********@sh awinc.com> wrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Marina,

I took the line out that sets objHeader to nothing to try it but my
variable is still coming out as nothing by the time the function gets
called.

Thanks again!

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
When would you be calling this method?

You are creating the object, setting a property, then setting the object
pointer to nothing - effectively meaning there are no more references to
this object, so nothing ever could call any methods on it. The object
will be garbage collected when the GC runs.

So there is no way you are calling any methods on the object. The object
never gets added to the page. You create it, set a property, then that's
it. Nothing else ever happens to it.

"David Hearn" <Da*********@sh awinc.com> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Setting the property from the Page_Load event of the parent page.

Parent Page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim objHeader As New Header
objHeader.PageN ame = "Stock Check"
objHeader = Nothing
End If
End Sub

Public property is listed below in original message. Then I am am
calling the function in the user controls Page_PreRender event per a
suggestion from someone else. SetHeaderInfo is the name of the function
and trying to pass strPageName as the variable that is set in the
property:

Private Sub Page_PreRender( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.PreRende r
SetHeaderInfo(s trPageName)
End Sub
Thanks!

"Marina Levit [MVP]" <so*****@nospam .com> wrote in message
news:Ot******** ********@TK2MSF TNGP03.phx.gbl. ..
> You need to show us when and how you are calling these functions.
> Also, exactly when you are setting the property.
>
>
> "David Hearn" <Da*********@sh awinc.com> wrote in message
> news:uV******** *****@TK2MSFTNG P04.phx.gbl...
>>I have a property in a user control that I am setting:
>>
>> Private strPageName as String
>> Public Property PageName() as String
>> Get
>> Return strPageName
>> End Get
>> Set(byVal Value as String)
>> strPageName = Value
>> End Set
>> End Property
>>
>> So why can't I access strPageName in any of my functions? I am
>> setting this property from the parent page that the user control is
>> in. It is always Nothing by the time I get to my functions even
>> though I can see it come in initially.
>>
>> Thanks in advance!
>>
>
>



May 4 '06 #7

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

Similar topics

3
2790
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different IDs. Thanks Vivek
1
2305
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of response.redirects to the same page. Because I hate the overhead by doing this I'm searching for a cleaner option. But I'm having troubles (off course or I wouldn't be posting this).
5
1511
by: Dan Nash | last post by:
Hi all, I've got a page with a user control on, added via VS. I'm trying to get to a property of the user control (or more precisely, a public var). Here's the code at the top of my aspx page... <%@ Register TagPrefix="dI2" TagName="dartsUC_rolodexsearch" Src="dartsUC_rolodexsearch.ascx" %>
3
1300
by: Lynn | last post by:
Hello, I have some user controls on a page...one for the user to fill in name, address, etc., and the other for the user to fill in credit card information. I have built the user controls in exactly the same way in that in the code behind page, I am using: Public Property sCVCCode() As String Get
3
1638
by: Craig G | last post by:
i have a user control which is basically a datagrid, which has add/edit/delete buttons on the grid is there anyway of accessing the actual datagrid from the form itself? basically i want to set the add/edit/delete options visble/invisible on the datagrid depending on the users's role, but found that i cannot access the grid to do this. is the only way of setting it in the page load of the usercontrol itself?
9
2445
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx"); ucline.Initializecontrol(line,alternate); Placeholder1.Controls.Add(ucline); }
6
4065
by: evandelagrammaticas | last post by:
Hi all. I have spent the better part of a day scouring the newsgroups and I am sure that I must have come across the solution a number of times - but I am still a real newbie at asp.net so please forgive me beforehand if I ask anything really simple or ridiculous. I am going to simplify my query... the structure of my example is ---> page1.aspx ------> page1.aspx.vb --->control1.ascx for the sake of simplicity this is what I am trying...
0
933
by: tshad | last post by:
I have a User Control with 4 Textboxes. I want to be able to access the properties (.text, .visible, .enable etc) directly from outside the Controls as the normal properties (.text, .visible etc). For example: at the moment I need to create a new property for each TextBox since I can't figure out how to set up "text" as a property. *********************************************
0
833
by: RSH | last post by:
I have a situation where I have developed a user control that contains several ImageButtons with hardcoded values. In the codebehind I have a property that is setup to receive a string value from the parent page. The properties value is also the name of the control. So what I am trying to do, is when the property is set I want to use the string value to reference the appropriate imagebutton and change the imageurl property without...
0
8411
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
8838
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
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
8513
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,...
0
8613
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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
4173
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
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.