Property

S

shapper

Hello,

I created a custom control as follows:

Public Class Field
Inherits Control
Implements INamingContainer

Protected Overrides Sub CreateChildControls()
MyBase.Controls.Add(tbInput)
MyBase.CreateChildControls()
Me.ChildControlsCreated = True
End Sub

' Value
Public Property Value() As String
Get
Return ViewState("Value")
End Get
Set(ByVal value As String)
ViewState("Value") = value
End Set
End Property ' Value

Private Sub tbInput_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles tbInput.Init
tbInput.Text = Me.Value
End Sub

End Class

I added this control to a web page in Page_Init event.
In the control Init event I defined its value as "Initial Value"

I then added a button to a page:

Private Sub bSubmit_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles bSubmit.Click
Response.Write(MyField.Value.ToString)
End Sub

When I click this button the value displayed is always "Initial Value"
even when it was changed.
And after the PostBack the value in the text box changes again Initial
Value.

Any idea what I am doing wrong?

Thanks,
Miguel
 
S

shapper

Hello,

I created a custom control as follows:

Public Class Field
Inherits Control
Implements INamingContainer

Protected Overrides Sub CreateChildControls()
MyBase.Controls.Add(tbInput)
MyBase.CreateChildControls()
Me.ChildControlsCreated = True
End Sub

' Value
PublicPropertyValue() As String
Get
Return ViewState("Value")
End Get
Set(ByVal value As String)
ViewState("Value") = value
End Set
EndProperty' Value

Private Sub tbInput_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles tbInput.Init
tbInput.Text = Me.Value
End Sub

End Class

I added this control to a web page in Page_Init event.
In the control Init event I defined its value as "Initial Value"

I then added a button to a page:

Private Sub bSubmit_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles bSubmit.Click
Response.Write(MyField.Value.ToString)
End Sub

When I click this button the value displayed is always "Initial Value"
even when it was changed.
And after the PostBack the value in the text box changes again Initial
Value.

Any idea what I am doing wrong?

Thanks,Miguel

Anyone?

Thanks,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top