Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > UserControl - Textbox tag property looses value on postback

Reply
Thread Tools

UserControl - Textbox tag property looses value on postback

 
 
Mike Dole
Guest
Posts: n/a
 
      11-15-2004
I experimented with a usercontrol (TagedTextbox), I added a tag
property.
The tag value however is not persisted on postback (text value's
fine)?

I worked around it with:

Me.ViewState("tag") = txtToelichting.Tag

but what's wrong with my code?



[Code Snippet:]

Imports System.ComponentModel
Imports System.Web.UI


Namespace Greenbay

<DefaultProperty("Text"), ValidationProperty("Text"),
ToolboxData("<{0}:TagedTextBox runat=server></{0}:TagedTextBox>")>
Public Class TagedTextBox
Inherits System.Web.UI.WebControls.TextBox
Implements INamingContainer

Private _tag As String

Public Property Tag() As String
Get
Return _tag
End Get
Set(ByVal Value As String)
_tag = Value
End Set
End Property
End Class
End Namespace

Thanks in advance,

Mike
 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      11-15-2004
Your subject says UserControl (ASCX files), but this is a server control
question (no problem, just wanted to make sure the terminology was
straight).

There's nothing wrong with your code, if you want the value to be persisted,
you need to store it in the viewstate as you did...there are no alternative,
unless you reset the value on postback in your page...your proprety should
probably look something like


public property Tag() as string
get
if ViewState("tag") is nothing then
'What to do? return default maybe?
else
Return cstr(ViewState("tag"))
end if
end get
set (byval value as string)
ViewState("tag") = value
end set
end property

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"Mike Dole" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> I experimented with a usercontrol (TagedTextbox), I added a tag
> property.
> The tag value however is not persisted on postback (text value's
> fine)?
>
> I worked around it with:
>
> Me.ViewState("tag") = txtToelichting.Tag
>
> but what's wrong with my code?
>
>
>
> [Code Snippet:]
>
> Imports System.ComponentModel
> Imports System.Web.UI
>
>
> Namespace Greenbay
>
> <DefaultProperty("Text"), ValidationProperty("Text"),
> ToolboxData("<{0}:TagedTextBox runat=server></{0}:TagedTextBox>")>
> Public Class TagedTextBox
> Inherits System.Web.UI.WebControls.TextBox
> Implements INamingContainer
>
> Private _tag As String
>
> Public Property Tag() As String
> Get
> Return _tag
> End Get
> Set(ByVal Value As String)
> _tag = Value
> End Set
> End Property
> End Class
> End Namespace
>
> Thanks in advance,
>
> Mike



 
Reply With Quote
 
 
 
 
Mike Dole
Guest
Posts: n/a
 
      11-16-2004
Thanks Karl,

It did the trick, but it still confuses me (the client / server /
session thing).
I know that's what it's all about but I just don't get it..

In vb.net I just say
car.speed = 50
start car
'car.started = true
'car.speed = 50

In asp.net I have to start the car (By pressing the start button =
postback my speed resets), I have to store the speed in a ViewState.

If I catch the speed viewstate in In the page_load event it's empty
because the 50's assigned in the btn_start click event and the
Page_load event's triggered before speed gets it's value.

If I want to do something with the ViewState I have to retrieve the
values in the Pre_Render event..

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
Panel1.BackColor = ViewState("BackColor")
End Sub


It seems like ASP.net is much more complicated...

But anyway thanks for your help it helped me a lot.

Regards,

Mike



"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:<(E-Mail Removed)>...
> Your subject says UserControl (ASCX files), but this is a server control
> question (no problem, just wanted to make sure the terminology was
> straight).
>
> There's nothing wrong with your code, if you want the value to be persisted,
> you need to store it in the viewstate as you did...there are no alternative,
> unless you reset the value on postback in your page...your proprety should
> probably look something like
>
>
> public property Tag() as string
> get
> if ViewState("tag") is nothing then
> 'What to do? return default maybe?
> else
> Return cstr(ViewState("tag"))
> end if
> end get
> set (byval value as string)
> ViewState("tag") = value
> end set
> end property
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/

 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      11-17-2004
It is..but in winforms the client is always connected, there is a constant
state "ON"...in ASP.Net it's "ON/OFF/ON/OFF/ON/OFF" with nothing connecting
the pieces together....without a doubt it's more complicated, but it's not
like they said "let's screw web developers!"...it's just how working with a
stateless environment works...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"Mike Dole" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Thanks Karl,
>
> It did the trick, but it still confuses me (the client / server /
> session thing).
> I know that's what it's all about but I just don't get it..
>
> In vb.net I just say
> car.speed = 50
> start car
> 'car.started = true
> 'car.speed = 50
>
> In asp.net I have to start the car (By pressing the start button =
> postback my speed resets), I have to store the speed in a ViewState.
>
> If I catch the speed viewstate in In the page_load event it's empty
> because the 50's assigned in the btn_start click event and the
> Page_load event's triggered before speed gets it's value.
>
> If I want to do something with the ViewState I have to retrieve the
> values in the Pre_Render event..
>
> Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles MyBase.PreRender
> Panel1.BackColor = ViewState("BackColor")
> End Sub
>
>
> It seems like ASP.net is much more complicated...
>
> But anyway thanks for your help it helped me a lot.
>
> Regards,
>
> Mike
>
>
>
> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>

wrote in message news:<(E-Mail Removed)>...
> > Your subject says UserControl (ASCX files), but this is a server control
> > question (no problem, just wanted to make sure the terminology was
> > straight).
> >
> > There's nothing wrong with your code, if you want the value to be

persisted,
> > you need to store it in the viewstate as you did...there are no

alternative,
> > unless you reset the value on postback in your page...your proprety

should
> > probably look something like
> >
> >
> > public property Tag() as string
> > get
> > if ViewState("tag") is nothing then
> > 'What to do? return default maybe?
> > else
> > Return cstr(ViewState("tag"))
> > end if
> > end get
> > set (byval value as string)
> > ViewState("tag") = value
> > end set
> > end property
> >
> > Karl
> >
> > --
> > MY ASP.Net tutorials
> > http://www.openmymind.net/



 
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
Postback problem with usercontrol in usercontrol Mark van Bree ASP .Net Web Controls 1 05-30-2006 08:27 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Getting a property of a control inside a usercontrol, from another usercontrol Fabiano ASP .Net 2 06-03-2005 09:56 AM
UserControl Looses ViewState when a hyperlink inside the control is clicked udit_handa@hotmail.com ASP .Net 0 05-16-2005 04:30 PM
RE: Textbox postback putting value,value =?Utf-8?B?QW5hY2hvc3RpYw==?= ASP .Net 1 06-21-2004 10:50 AM



Advertisments