473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

UserControl - Textbox tag property looses value on postback

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
Nov 18 '05 #1
3 9210
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" <m_******@hotmail.com> wrote in message
news:fd**************************@posting.google.c 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

Nov 18 '05 #2
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:<e6**************@tk2msftngp13.phx.gbl>...
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/

Nov 18 '05 #3
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" <m_******@hotmail.com> wrote in message
news:fd**************************@posting.google.c 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:<e6**************@tk2msftngp13.phx.gbl>...
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/

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Maurice Mertens | last post by:
Hi, having some troubles with a BOUND textbox. The BOUND (text property) textbox is hidden on the form. Just before I update the database I stopped the code in debug and when I use me.C_ID.text...
4
by: Gill Smith | last post by:
After setting the web control text box enable property to FALSE makes the control to loose the data between round trip. I am making sure that the property - EnableViewState = TRUE. Same code...
3
by: Henry | last post by:
Hi. I've also posted this at another discussion board and here is the original question. ------------------------- "I have this problem and I don't know what I can do. First of all, I have a...
2
by: ABC | last post by:
How to pre-set combo textbox's selectedindex value from querystring passed from another page? I pass the querystring to set combo text box (change selectedindex on Page_Init). Source code as: ...
1
by: Dave Wurtz | last post by:
All, I have a custom control that has a textbox on it. I want to be able to set properties of the textbox in the IDE. I have exposed the textbox with a property and it now shows up in my...
1
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle...
1
by: =?Utf-8?B?Tmltcm9kIFJvdG5lcg==?= | last post by:
Hi, I built a web control wich has text box and public property that set or get the text value of that text box. when i try to access that property i got error: "Object reference not set to an...
1
by: dotnetguys | last post by:
Hi there, I want to pass textbox server control value through anchor tag to some other form how do i do Can somebody help me for this. Thanks
1
by: shapper | last post by:
Hello, I have two properties in a custom control. One is of a boolean type and the other is an enum type. How can I define a default value when they are not defined? Here is my code: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.