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

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 1503
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
1
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...
5
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...
3
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...
3
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...
9
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");...
6
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...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.