简体   繁体   中英

Fire textbox OnTextChanged event dynamically

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)

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

http://www.aspdotnet-suresh.com/2011/05/ajax-autocompleteextender-sample.html

please refer this link and apply it to your program... this is damm easy.... You will not need further assistance or help afterwards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM