473,788 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("t ag") = txtToelichting. Tag

but what's wrong with my code?

[Code Snippet:]

Imports System.Componen tModel
Imports System.Web.UI
Namespace Greenbay

<DefaultPropert y("Text"), ValidationPrope rty("Text"),
ToolboxData("<{ 0}:TagedTextBox runat=server></{0}:TagedTextBo x>")>
Public Class TagedTextBox
Inherits System.Web.UI.W ebControls.Text Box
Implements INamingContaine r

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 9234
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_******@hotma il.com> wrote in message
news:fd******** *************** ***@posting.goo gle.com...
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("t ag") = txtToelichting. Tag

but what's wrong with my code?

[Code Snippet:]

Imports System.Componen tModel
Imports System.Web.UI
Namespace Greenbay

<DefaultPropert y("Text"), ValidationPrope rty("Text"),
ToolboxData("<{ 0}:TagedTextBox runat=server></{0}:TagedTextBo x>")>
Public Class TagedTextBox
Inherits System.Web.UI.W ebControls.Text Box
Implements INamingContaine r

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.EventArg s) Handles MyBase.PreRende r
Panel1.BackColo r = ViewState("Back Color")
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******* *******@tk2msft ngp13.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....wit hout 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_******@hotma il.com> wrote in message
news:fd******** *************** ***@posting.goo gle.com...
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.EventArg s) Handles MyBase.PreRende r
Panel1.BackColo r = ViewState("Back Color")
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******* *******@tk2msft ngp13.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
409
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 it gives back the value "". When I make the control visible it suddenly does have a value. Can't a hidden textbox have a value then???
4
3588
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 when the text box Enable property set to TRUE retains the value. Please advice. -Gill
3
1710
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 page with and button, and 5 <asp:TextBox>'s and when an user makes changes to each of the textbox content, javascript client side code is triggered to change the textbox background color property to some other color. My problem is when I click...
2
2133
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: Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init If Not (Page.IsPostBack) Then
1
1529
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 properties window in the IDE. I can set attributes (i.e. character casing, etc.) but it will not 'save' those settings by writing it back to the source code. What am I doing wrong here? Public MyControl
1
6870
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 and page loading/rendering lifecycle.... Ok, now for the question: I have an ASPX page (page.aspx), and I have a UserControl (control.ascx). The UserControl has one textbox on the control, and one button control. I have added a public property...
1
2226
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 instance of ..." the compilation has no detected problem and i do not understand what is the problem.
1
3253
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
1101
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: Private _AutoPostBackOnSelect As Boolean
0
10173
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.