?
Solved

Sharing values between user controls vb.net

Posted on 2005-03-20
10
Medium Priority
?
302 Views
Last Modified: 2011-10-03
I am newbie and I have a simple question here. I developed a user control1  "partdetail.ascx"  which gets a value from the database and sets that value to a variable.
something as easy as:

*******
Private Counter  As Integer = 0
counter= db.Parameters("@RowCount").Value
*******
No problem here, but
I have another usercontrol "partsummary.ascx"  and I want this 2nd user control to display the value from the "counter" variable that was set in the 1st usercontrol.

How can I do that?

I know that you can create a custom property but I haven't been able to find out how to do it.

any help will be appreciated!!! very urgent! please be as detailed as possible.
0
Comment
Question by:pimplicado
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
10 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13589819
in your usercontrol just add

    Public ReadOnly Property Counter() As Integer
        Get
            Return m_counter
        End Get
    End Property

then you should be able to reach it like

textbox1.text = usercontrol1.Counter


0
 
LVL 18

Expert Comment

by:tusharashah
ID: 13590851
Check out different approachs in passing value between ASPX and ASCX pages:

http://www.c-sharpcorner.com/Code/2005/Jan/PassingValuesfrmUCtoASPX.asp

-tushar
0
 

Author Comment

by:pimplicado
ID: 13598883
Thanks for the answer but still this does not make sense... (I know it is something easy but It does not work for me)

Ok

I added the property as indicated

This is what I did...

Class partdetail.ascx
 Private m_counter as Integer = 0   'step 1

 Then In the PageLoad I call getDetail  'step 2

  Public Sub getDetail  'step 3 getDetail sets the value for counter

  m_counter= db.Parameters("@RowCount").Value ' this should be 30
 
 End Sub

Public ReadOnly Property Counter() As Integer ' step 4
        Get
            Return m_counter  
        End Get
    End Property

end class

OK in my 2nd usercontrol

I do the following

class partsummary
 
Dim partCounter As New myUserControl.partdetail

        lblCount.Text = partcounter.Counter

End Class

However this label displays zero or whatever value I set when I do the
Private m_counter as Integer = 0 in the 1st user control.

Why if I changed the value of m_counter in the sub getDetail I only get zero when I try to access this value in my 2nd user control?

I hope I explained myself.

Thanks for your help.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13599160
shouldn't it be

Dim partCounter As New myUserControl.partdetail
        partcounter.getdetail
        lblCount.Text = partcounter.Counter
End Class
0
 

Author Comment

by:pimplicado
ID: 13603501
the gedetail sub expects parameters that are set in the usercontrol.

I just want to be able to use the value of counter in the 2nd user control.
it seems that I am able to get it but as I tried to explain before
when I declare counter as Private m_counter as Integer = 0   this value remains as zero regardless if
I assign a new value let's say m_counter = 30 in a sub inside of the 1st user control

It seems that this property is ignoring  the value that I set in the sub and it is accepting only the zero from the declaration.
what I get in the 2nd user control is zero. or 1 or whatever value I use in the declaration line.
Public ReadOnly Property Counter() As Integer
        Get
            Return m_counter  
        End Get
    End Property

end class

I am not allowed to change that value in the 1st user control??
help please!
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13609274
try it like this

Public Property Counter() As Integer ' step 4
        Get
            Return m_counter  
        End Get
        Set(ByVal Value As Integer)
            m_counter = value
        End Set

    End Property

than set it  from the other

like

usercontrol2.counter =

0
 

Author Comment

by:pimplicado
ID: 13613910
the problem is that I don't need to set the value of counter in usercontrol2
I want to ACCESS the value set in usercontrol1.

Let me change the question...

I have a field called counter in USER CONTROL #1
How can I access the value of counter in USER CONTROL #2?

CLASS USERCONTROL1

page load
getdetail()
end


sub getdetail()
counter = 50
end sub

END CLASS

Now in usercontrol 2
I want to say

CLASS USERCONTROL2
page load
label1.text = counter ' this should be 50
end
END CLASS

0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13619775
Ok it is getting more clear, are these usercontrols the same ?
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 1500 total points
ID: 13619833
Well actually it doesn't matter, What you want is possible but it would make the usercontrol useless in any other form you want to use it in.

this is how it is possible

in usercontrol2 do something like this

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        label1.Text = DirectCast(Me.Parent, Form2).UserControl11.counter
    End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question