Automatic event firing in a textbox while text is

2019-08-31 12:02发布

问题:

I m designing a spell checker for Indian language in asp.net using c#.

I have prepared all the modules. But, there is a problem using TextBox as I want it to tell the error while user types in the text and highlight that string.

I have done this on a button click but I am not able to do it directly without any button. Is it possible using jquery or ajax tools to use a TextBox for firing an event while text is being typed? (I tried TextChanged event but it gets fired only when a Button is clicked in asp.net)

回答1:

You can just use the TextChanged event handler.

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
           TextBox tmp = sender as TextBox ;
           if(SpellCheck(tmp.Text))
           {
                    // No Error.
           }
           else
           {
                 // Error 
           }
    }
   // SpellCheck is a function checking the spelling(which you have to make.)  

Make sure that

    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox> 

is there in your code.



回答2:

you can use onkeyup of javascript



回答3:

You can use change event and make to ajax call inside that event.

$( ".target" ).change(function() {
 //make ajax call to u'r function
});