asp.net textchanged for textbox

  • Thread starter Thread starter rodchar
  • Start date Start date
R

rodchar

hey all,

is there a way to get the previous value in a textchanged event of a textbox
(or any control for that matter)?

Advice on any other way to do this is welcomed too.

thanks,
rodchar
 
I don't believe there is a built-in way to do it, but a relatively simple
way to get that information would be to use the onfocus JavaScript event to
assign the current value to a HiddenField control, as in the following:

onfocus="document.getElementById('hdnPrevValue').value=this.value;"

Take note that you will need to dynamically generate this JavaScript since
the id of the HiddenField will not be exactly what you enter in your *.aspx
file (to do this you will use the ClientId property). If you are planning to
need to get the previous value for a large number of TextBoxes, you could
even write your own custom control that inherits from TextBox to do this.
Hopefully this helps.
 
thanks for the feedback and help,
rod.

Nathan Sokalski said:
I don't believe there is a built-in way to do it, but a relatively simple
way to get that information would be to use the onfocus JavaScript event to
assign the current value to a HiddenField control, as in the following:

onfocus="document.getElementById('hdnPrevValue').value=this.value;"

Take note that you will need to dynamically generate this JavaScript since
the id of the HiddenField will not be exactly what you enter in your *.aspx
file (to do this you will use the ClientId property). If you are planning to
need to get the previous value for a large number of TextBoxes, you could
even write your own custom control that inherits from TextBox to do this.
Hopefully this helps.
 
Back
Top