0

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

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by reach_yousuf
0

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

Edited by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.