textbox changed event

  • Thread starter Thread starter jonathandrott
  • Start date Start date
J

jonathandrott

hi,

I'm trying to update a label with the text in a textbox as the user
types in the information.

something like this is not working:

Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs)

label1.text = me.textbox1.text

End Sub

I want to update the label for every key stroke.
 
I suggest you do this from the client side .. it is much more
efficient in terms of resources and certainly much faster.

On page load add this code:

if(!Page.IsPostBack)
TextBox1.Attributes.Add("onChange","label1.value=textbox1.value");
 
i'm using the new ajax extensions to update the events. resources are
not a problem. this is being used for a specific purpose. is it
possible to change the label with each keystroke?
this is being done in visual web developer 2005.
 
The problem, though, is that the textChanged event only fires once the focus
is lost from the TextBox.
 
I'm not sure if that is possible using the current implementation of
asp.net.

The textchanged event fires when the text as a whole changes, not when
a character in the textbox changes.

You might have to do a little more work to achieve what you're lookng
for.

I suspect you might have to write a client side javascript function to
handle the keydown event and in that function submit the form.

Still, the latency of this approach is likely to be an issue
 
yes, now you understand the problem i'm running into. is there an easy
way to change this?
 
hi,
call a javascript method with page registerstartupscript method
with the object which you want to focus() at startup.

Page.RegisterStartupScript("focus","<script>SetFocus('"+txtbox1.ClientID+"');");

function SetFocus(obj)
{
document.getElementById(obj).focus();
}

Asp.net isnt only a server side programing. you should have to use
javascript for developing web apps.
 
Back
Top