Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

TextBox and Property

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shapper - 06 Dec 2007 17:06 GMT
Hello,

I am working on Library which will include various controls.

One of these controls has a TextBox.

I am using a property named Value to define the TextBox text:

   ' Value
   Private _Value As String
   Public Property Value() As String
     Get
       Return _Value
     End Get
     Set(ByVal value As String)
       _Value = value
     End Set
   End Property ' Value

And the TextBox Init event is the following:

   Private Sub tbText_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles tbText.Init
      tbText.ID = "tbText"
      tbText.Text = _Value
   End Sub

I added this control to a page and defined its value to "Hello".

I also added a button to the page that when clicked basically does
Response.Write(MyControl.Value)

What happens is that when I change the TextBox text to "Goodbye" and
click the button the text that Response.Write outputs is "Hello".

Why isn't the property returning the new value?

What is the right way to do this?

Thanks,

Miguel
Milosz Skalecki [MCAD] - 06 Dec 2007 19:41 GMT
Howdy,

This is because you change the text of the text box in the Init event.
Button raises its Click event between Load and PreRender page's events
meaning after you take the value of the Value property. In addition, if the
value is set through the code or data binding its value will be lost because
it's not stored in the viewstate. You need to simplify your code to:

Public Property Value() As String
     Get
       Return tbText.Text
     End Get
     Set(ByVal value As String)
       tbText.Text = value
     End Set
End Property ' Value

Done

hope it helps
Signature

Milosz

> Hello,
>
[quoted text clipped - 38 lines]
>
> Miguel

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.