2

Hi how can i register and call a server side event for onkeyup event in asp.net textbox.

Is it possible?

thank you

jestges
  • 3,686
  • 24
  • 59
  • 95
  • It's possible but why you want to used it. – santosh singh Feb 10 '11 at 06:17
  • 1
    I'd suggest doing the keyup event in JavaScript (on the client) and making an AJAX call to the server side. I'd also be very careful because the keyup event has the potential to be called multiple times (that is a lot of times) and your server side processing needs to be really performant in order to be able to pull this off. – Shiv Kumar Feb 10 '11 at 06:17
  • Hi thank you for ur response. Can you give me a simple example – jestges Feb 10 '11 at 06:30

1 Answers1

4

TextBox Web control doesn't provide onkeyXXX events instead subscribe to OnTextChanged event;

<asp:TextBox ID='Textbox1' runat='server' OnTextChanged='HandleTextbox1OnTextChanged'>
    </asp:TextBox>

public void HandleTextbox1OnTextChanged(Object sender, EventArgs e)
    {

    }

But you can provide onkeyXXX behavior from client-side.

You can add client-side handler like :

Textbox1.Attributes.Add("onkeyup", String.Format("onKeyUp({0})", TextBox1.ID));

And in the page

`<script language='javascript' type='text/javascript'>
   function onKeyUp(id) { //do something; } 
</script>`

Also you could use PageMethods to make a call to server-side web methods (static methods) from javascript functions.

This link might help.

Vijay Sirigiri
  • 4,653
  • 29
  • 31