Hello,

I have a custom control I have made and I would like to use a dynamic variable assigned in the code behind of the aspx page.

I would like to pass a variable called topic to the control.
Here is the property of the control:

Property Topic() As String
        Get
            Return _Topic
        End Get
        Set(ByVal value As String)
            _Topic = value
        End Set
    End Property

The control is placed as so in the front end of my aspx page:

<MYControl:MY runat="server" id="MYID" Topic="TEST" />

and in the page load of the code behind I have:

MYID.Topic = "something"

With all of the above considered, the topic variable is sent as Test, and not something.
If I remove Topic=Test from the tag on the front end, then Topic is sent as null. I have tried so many different variations but for some reason Topic is always null. Every solution I seem to come accross seems to suggest I do what I have just posted. The only thing I am asking to do is be able to dynamically set the topic variable in code behind.

Use ViewState.

Property Topic() As String
        Get
            If IsNothing(ViewState("Topic")) Then
                Return String.Empty
            Else
                Return ViewState("Topic").ToString()
            End If
        End Get
        Set(ByVal value As String)
            ViewState("Topic") = value
        End Set
    End Property
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.