HighTechTalks DotNet Forums  

Property

ASP.net ASP.net discussions (microsoft.public.dotnet.framework.aspnet)


Discuss Property in the ASP.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
shapper
 
Posts: n/a

Default Property - 12-19-2007 , 07:57 PM






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

Reply With Quote
  #2  
Old   
shapper
 
Posts: n/a

Default Re: Property - 12-21-2007 , 02:33 PM






On Dec 20, 12:57 am, shapper <mdmo... (AT) gmail (DOT) com> wrote:
Quote:
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


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.