what is the alternate event of Textbox.KeyDown of Winform in WebForm in C# asp.net?

前端 未结 3 1898
青春惊慌失措
青春惊慌失措 2021-01-28 08:08

In winfrom applications i can have

textbox1.keydown 

event, but i want to achieve same thing in webform (asp.net), so how can i do that? I need

3条回答
  •  走了就别回头了
    2021-01-28 08:55

    In web application there are something you do in the client and some in the server.

    I don't now what you what achieve, but i think that in most cases rise the keydown event will be in the client.

    SO, there is a great library called JQUERY (javascript) that helps you do this kind of staff.

    see the documentation of KEYDOWN

    I wrote an example for you

    HTML Code

    JQUERY (javascript) Code

    $(document).ready(function() {
    
    $("#txtBox").keydown(function() {   
       $.ajax({
       url: "URLTOTHEFUNCTIONINTHESERVER",
       type: 'GET',
       cache: false
       }).done(function( html ) {
        alert(html);
        });
    });
    
    });​
    

    OK to explain the code

    • The first line i am checking if the document is ready
    • then i caching the keydown event and firing a function
    • Inside the function i am calling to an ajex function of jquery, inside the function you will see a "done" functio nand a var called html which hold the content that returns from the server

提交回复
热议问题