textbox changed event

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.
 
R

Rad [Visual C# MVP]

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");
 
J

jonathandrott

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.
 
D

David Wier

The problem, though, is that the textChanged event only fires once the focus
is lost from the TextBox.
 
R

Rad [Visual C# MVP]

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
 
J

jonathandrott

yes, now you understand the problem i'm running into. is there an easy
way to change this?
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top