Accessing a code behind function on keypress event

Accessing a code behind function on keypress event

Page 1 of 1

4 Replies - 9275 Views - Last Post: 14 October 2008 - 07:06 AM Rate Topic: -----

#1 penn.nila  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 13-October 08

Accessing a code behind function on keypress event

Posted 13 October 2008 - 10:21 PM

I havent wriiten an code. i just wanted to know how to call a codebehind function on keypress even in c#. is it possible to call a server side function when a key in? Please give me the code snippets example of any text box keypress event. syntaxt of the event call.

This post has been edited by penn.nila: 13 October 2008 - 10:24 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Accessing a code behind function on keypress event

#2 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Accessing a code behind function on keypress event

Posted 14 October 2008 - 02:59 AM

If you just double click it in design view it will automatically add a method called void TextBox1_TextChanged()

That's the function that you should edit~

:)

(Note that if you want to do it yourself, you can)
this.textBox1.TextChanged += new System.EventHandler(myEventHandler);


Then, your event handler function should look like this:
void myEventHandler(object sender, EventArgs e) {
    // do stuff here
}

Hope this helps :)
Was This Post Helpful? 0
  • +
  • -

#3 penn.nila  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 13-October 08

Re: Accessing a code behind function on keypress event

Posted 14 October 2008 - 03:23 AM

Hey dude!

Thanks a lot for the swift reply.

Cheers, GBU. :)

View Postgabehabe, on 14 Oct, 2008 - 02:59 AM, said:

If you just double click it in design view it will automatically add a method called void TextBox1_TextChanged()

That's the function that you should edit~

:)

(Note that if you want to do it yourself, you can)
this.textBox1.TextChanged += new System.EventHandler(myEventHandler);


Then, your event handler function should look like this:
void myEventHandler(object sender, EventArgs e) {
    // do stuff here
}

Hope this helps :)

Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Accessing a code behind function on keypress event

Posted 14 October 2008 - 05:38 AM

I don't think that is what you want to do. since you said "server side function", I will assume this is in ASP.Net(you probably should have posted this in the ASP.Net forum). calling a server side function will cause you to do a postback. doing a postback on every keypress is HIGHLY inefficient.

you will want to use javascript.
Was This Post Helpful? 0
  • +
  • -

#5 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Accessing a code behind function on keypress event

Posted 14 October 2008 - 07:06 AM

Didn't see that bit :blush:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1