asp.net bind textBox to an object

Hello together,

I want to bind a textBox to an object like the following.

Thank you in advance.
Public Class Test
    Private strTest As String
    Public Property usingTest() As String
        Get
            Return Me.strTest 
        End Get
        Set(ByVal value As String)
            Me.strTest = value
        End Set
    End Property
End class
 
'in another class I generate a TextBox
dim tst as new Test
dim txt01 as new TextBox
 
'something like this
'txt01.Text = "<%# Container.DataItem('tst.usingTest') %>"
'txt01.Text = "<%#tst.usingTest%>"

Open in new window

GaialaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Oliver AmayaEntrepeneurCommented:
Hi, something like this?
dim tst as new Test
dim txt01 as new TextBox
 
txt01.Text = tst.usingTest

Open in new window

0
GaialaAuthor Commented:
no that does not work.
0
Oliver AmayaEntrepeneurCommented:
Do you get an error?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

GaialaAuthor Commented:
I don't get an error.  The problem is that at this time tst.usingTest is always  emty.
The textbox belongs to a templatefield (gridView).
0
Oliver AmayaEntrepeneurCommented:
Ok, but when are you setting it's value? the code I showed was just an example of how to call the usingTest property. At some point you would need to do something like this:
tst.usingTest = "Some Value"

Open in new window

0
GaialaAuthor Commented:
here my code
'the class FillObjects
For Each ndChild As XmlNode In ndItem.ChildNodes
   xmlTest = New GridContents
   '...
   xmlTest.stateProperty() = tempString 'has a value
   '....
 
'the class GridContents
 Public Property stateProperty() As String()
        Get
            Return Me.strState
        End Get
        Set(ByVal value() As String)
            Me.strState= value
        End Set
 End Property
 
'I have GridView which contains TemplateFields
 
Dim templField As New TemplateField
templField.HeaderText = strHeaderText
templField.Visible = True
templField.ItemTemplate = New TestTemplate
testGrid .Columns.Add(templField)
 
'the implementation of TestTemplate looks like
Sub InstantiateIn(ByVal container As Control) Implements System.Web.UI.ITemplate.InstantiateIn
        Dim txtControl As New TextBox
        Dim lblControl As New Label
         lblControl.ID = "lblCon"
        txtControl.ID = "txtBox"
        Dim cl_TC As New GridContents
        Dim tempStr() As String
      
        txtControl.Text = cl_TC.StateProperty 'the value is always empty
        container.Controls.Add(lblControl) 
        container.Controls.Add(txtControl)
 End Sub

Open in new window

0
Oliver AmayaEntrepeneurCommented:
It's empty because you haven't assigned anything to it, in you InstantiateIn method you create a new object of type GridContents and that's it, you don't do anything else with it, meaning that the StateProperty will always be empty.
Dim cl_TC As New GridContents
txtControl.Text = cl_TC.StateProperty 'the value is always empty

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GaialaAuthor Commented:
oh sure, you are right!!!
so where is no possibility to get the already instantiated objects to bind on the textbox?
0
Oliver AmayaEntrepeneurCommented:
Depends on what you're doing after you set the value in the code below, is this getting saved to an xml file after you set the value? if so you would have to read the contents of that XML file whenever you want to set the textbox's value.
For Each ndChild As XmlNode In ndItem.ChildNodes
   xmlTest = New GridContents
   '...'
   xmlTest.stateProperty = tempString 'has a value'
   '....'

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.