Abbas
Abbas

Reputation: 5044

TextBox keydown event at server side in asp.net

i have a textbox on a page, now whenever any age number is entered in that page, that page should be loaded in my datalist, i have created rest of the thing, but i am not getting how to trigger the textbox onkeydown event from asp.net, i know working with that from javascript, but the problem is i have below things done in that function:

  • it applies the currentpage value to the static variable from textbox
  • it binds the datalist
  • it enable disable the next previous buttons accordingly
  • and i dont think this i can do from javascript, anyone have any resolution, how this could be achieved from server side, onkeydown event

    Upvotes: 3

    Views: 10256

    Answers (2)

    skub
    skub

    Reputation: 2306

    You can capture the keydown event in a javascript function then do a AJAX call to the server. If this does not suit you, then you could try manually do postback in javascript.

    So in your textbox:

    mytextBox.Attributes.Add("onkeydown", "return doDataListBind()");
    

    Now in the javascript function:

    function doDataListBind()
    {
          __doPostBack("myTextBox"); // etc, etc
         // some other code here...
    }
    

    More info can be found here:

    Upvotes: 2

    Pasha Immortals
    Pasha Immortals

    Reputation: 839

    Try looking into or using either:

    AJAX Control Toolkit, or

    JQuery Autocomplete Plugin

    Alternatively you could try to call _postback() function from a client side event/function for your textbox in javascript

    Upvotes: 0

    Related Questions