Automatic event firing in a textbox while text is being typed

那年仲夏 提交于 2019-12-25 07:02:56

问题


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
});


来源:https://stackoverflow.com/questions/21257663/automatic-event-firing-in-a-textbox-while-text-is-being-typed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!