Hi
I'm trying to set a property in the User Control. I see that the property is set when I'm debugging. But when I'm using the property in a method in the User Control the property is set to 0 everytime. I don't understand why.

Here is the code I'm using
This is the User Control in the Parent Page aspx

<uc1:SearchClickImage id="uclShowImage" runat="server"  />

Here is the code when I set the property in the Parent Page

uclShowImage.WhatNr= 3

The property code in the User Control

Private _whatNr As Integer

Public Property WhatNr() As Integer
        Get
            Return _whatNr
        End Get
        Set(ByVal value As Integer)
            _whatNr = value
        End Set
    End Property

And the event that uses the property in User Control

Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
   Select Case _whatNr 'Its here the _whatNr is 0. I also tried with 'WhatNr with the same result   
                Case 0
                ' Do something 
               Case 1
                'Do something  
               Case 2
                 'Do something  
 End Select
End Sub

Hope someone can help me to understand what I'm doing wrong

Thanks
Fia

Hi
I'm trying to set a property in the User Control. I see that the property is set when I'm debugging. But when I'm using the property in a method in the User Control the property is set to 0 everytime. I don't understand why.

Here is the code I'm using
This is the User Control in the Parent Page aspx

<uc1:SearchClickImage id="uclShowImage" runat="server" />

Here is the code when I set the property in the Parent Page

uclShowImage.WhatNr= 3

The property code in the User Control

Private _whatNr As Integer

Public Property WhatNr() As Integer
        Get
            Return _whatNr
        End Get
        Set(ByVal value As Integer)
            _whatNr = value
        End Set
    End Property

And the event that uses the property in User Control

Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
   Select Case _whatNr 'Its here the _whatNr is 0. I also tried with 'WhatNr with the same result
                Case 0
                ' Do something 
               Case 1
                'Do something  
               Case 2
                 'Do something  
 End Select
End Sub

Hope someone can help me to understand what I'm doing wrong

Thanks
Fia

Hi

Try to Get and Set values by using sessions

Public Property WhatNr() As Integer
        Get
            Return session("_whatNr")
        End Get
        Set(ByVal value As Integer)
            session("_whatNr") = value
        End Set
    End Property

Mark as solved if it helps you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.