Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > TextBox and Property

Reply
Thread Tools

TextBox and Property

 
 
shapper
Guest
Posts: n/a
 
      12-06-2007
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
 
Reply With Quote
 
 
 
 
Milosz Skalecki [MCAD]
Guest
Posts: n/a
 
      12-06-2007
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
--
Milosz


"shapper" wrote:

> 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide textbox / Make textbox not visible (NOT USING visible property) Jurjen de Groot ASP .Net Web Controls 0 05-19-2008 09:50 AM
create textbox at run time and insert data from textbox to database tanmaypatankar ASP .Net 0 12-18-2007 03:47 PM
WML Input and .NET TextBox not displaying Text Property erikpaulmiller@gmail.com ASP .Net Mobile 0 11-10-2005 06:21 PM
Custom Attributes (AttributeTargets.Property) and Property Type Zarko Gajic ASP .Net Building Controls 0 04-07-2005 02:20 PM
Re: VERY STRANGE BUG? Adding a textbox control causes other textbox control to fail??? S. Justin Gengo ASP .Net 0 07-16-2003 06:51 PM



Advertisments