Another way to put labels on page than asp:label

Another way to put labels on page than asp:label

Post by tsha » Sat, 09 Apr 2005 03:48:28


Is there another way to put labels on a page other than asp:label?

I have been building a page where I use a label to display the calculated
result of some imput. I do it using Javascript. But since the asp:label
equates to a <span> I have to create nodes to display the new text. The
problem is that as soon as I change pages (whether by post or just using a
back button), I lose whatever changes I made.

I don't have that problem with a Textbox.

The reason I am using Javascript is I don't want to make round trips to the
server, just to format the text and display on the page (something easily
done in Javascript).

Thanks,

Tom
 
 
 

Another way to put labels on page than asp:label

Post by Bruce Bark » Sat, 09 Apr 2005 08:44:37

create a hidden field (name it to match label). the javascript can update
both, on page load (client side), have it fetch the label from the hidden
field.

-- bruce (sqlwork.com)

 
 
 

Another way to put labels on page than asp:label

Post by tsha » Sat, 09 Apr 2005 09:00:25


That might work.

Just to make sure I understand what you are suggesting.

I have an asp:textbox. I have an asp:label. I have an hidden field (input
type=hidden...) - do I need to have this runat=server and does it need to be
a form field?

Are you saying to name the asp:label and hidden field with the same ID? I
thought you couldn't do that?

In my javascript, I have an onChange event on my textbox (actually set from
asp.net). When the user puts a value in the box, I go to my javascript and
format the data and set the asp:label (which is now a SPAN). This is what I
do now which works. In the same function I would also set the hidden field
to the same as the SPAN. For example I have the textbox set to 100, and the
SPAN and Hidden field are set to $100.00.

Now you are saying that I should set up an onLoad event in the Body Tag to
go move the $100.00 back to the SPAN from the hidden field?

Seems like it would work.

Does the onLoad event get called when the user hits his back button and then
the forward button so that the page is redisplayed?

Thanks,

Tom