469,913 Members | 2,534 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

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 1381
You need to show us when and how you are calling these functions. Also,
exactly when you are setting the property.
"David Hearn" <Da*********@shawinc.com> wrote in message
news:uV*************@TK2MSFTNGP04.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.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim objHeader As New Header
objHeader.PageName = "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.EventArgs) Handles MyBase.PreRender
SetHeaderInfo(strPageName)
End Sub
Thanks!

"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:Ot****************@TK2MSFTNGP03.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*********@shawinc.com> wrote in message
news:uV*************@TK2MSFTNGP04.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*********@shawinc.com> wrote in message
news:%2****************@TK2MSFTNGP05.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.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim objHeader As New Header
objHeader.PageName = "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.EventArgs) Handles MyBase.PreRender
SetHeaderInfo(strPageName)
End Sub
Thanks!

"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:Ot****************@TK2MSFTNGP03.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*********@shawinc.com> wrote in message
news:uV*************@TK2MSFTNGP04.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****************@TK2MSFTNGP04.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*********@shawinc.com> wrote in message
news:%2****************@TK2MSFTNGP05.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.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim objHeader As New Header
objHeader.PageName = "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.EventArgs) Handles MyBase.PreRender
SetHeaderInfo(strPageName)
End Sub
Thanks!

"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:Ot****************@TK2MSFTNGP03.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*********@shawinc.com> wrote in message
news:uV*************@TK2MSFTNGP04.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*********@shawinc.com> wrote in message
news:%2****************@TK2MSFTNGP03.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****************@TK2MSFTNGP04.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*********@shawinc.com> wrote in message
news:%2****************@TK2MSFTNGP05.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.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim objHeader As New Header
objHeader.PageName = "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.EventArgs) Handles MyBase.PreRender
SetHeaderInfo(strPageName)
End Sub
Thanks!

"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:Ot****************@TK2MSFTNGP03.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*********@shawinc.com> wrote in message
news:uV*************@TK2MSFTNGP04.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****************@TK2MSFTNGP05.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*********@shawinc.com> wrote in message
news:%2****************@TK2MSFTNGP03.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****************@TK2MSFTNGP04.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*********@shawinc.com> wrote in message
news:%2****************@TK2MSFTNGP05.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.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim objHeader As New Header
objHeader.PageName = "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.EventArgs) Handles MyBase.PreRender
SetHeaderInfo(strPageName)
End Sub
Thanks!

"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:Ot****************@TK2MSFTNGP03.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*********@shawinc.com> wrote in message
> news:uV*************@TK2MSFTNGP04.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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Vivek Sharma | last post: by
1 post views Thread by Kris van der Mast | last post: by
5 posts views Thread by Dan Nash | last post: by
3 posts views Thread by Lynn | last post: by
9 posts views Thread by Anders K. Jacobsen [DK] | last post: by
6 posts views Thread by evandelagrammaticas | last post: by
reply views Thread by tshad | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.