0
votes

I am working with AJAX and ASP.NET, I have a page with 2 textboxes and 1 label in an update panel, I want the OnTextChanged event to fire whenever the user types something in the textbox.

Right now, I got it working but it only fires the event after the user finishes typing and loses focus from the textbox, how can I get it to fire the event EVERYTIME the user types something.. Like this:

A > (fires event) > P > (fires event) > P > (fires event) > L > (fires event) > E (fires event)

1
Attach an event handler for the onkeyup? - melancia
tried adding "onKeyUp='textbox_TextChanged'" to both tbxQuantity and tbxPrice, it still doesn't fire the event dynamically when typing. - InnovativeDan
You can't do that on the tag itself. You need to write Javascript code. Also, what's gonna be fired can't be handled on the server side, unless you do a bit more work. - melancia
have u used autocomplete extender??? - The Hungry Dictator
@MelanciaUK actually what I want to do is quite simple, just getting the value of tbxQuantity * tbxPrice, but I just can't get it working. Is it possible to do that with javascript without server's intervention? - InnovativeDan

1 Answers

0
votes

you have to Register the Client Script that triggers the Event. the client script shall be javascript. and mind that you make AJAX call to communicate to the server Instead of POSTBACKING..

string scriptTest = "";

scriptText += @"function DisplayCharCount() {";
scriptText += "   spanCounter.innerText = " +
                 "document.forms[0].TextBox1.value.length";
scriptText += "}";

ClientScript.RegisterClientScriptBlock(this.GetType(), "CounterScript", scriptText, True);

TextBox1.Attributes.Add("onkeyup", "DisplayCharCount()");