By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,320 Members | 2,198 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,320 IT Pros & Developers. It's quick & easy.

How to activate button click event using enter button

P: 1

I have designed a web part using VS 2003 (Web control library template). I need to publish that in share point. Its not like drag and drop the things from toolbar. Every thing I need to do in code behind side.

I have a button and text box

Button Id: btnSearch
TextBox id: txtSearch

Button performs search operation. I need to enter a text to be searched and when I click button means the button click event is activated. That is search function is activated and we can view the records in data grid.

What I need is that if I press the enter button inside the text box means the search function need to be done. In other words button click event should be fired and correspondingly data grid should be viewed.

I used key press event but it is not firing.
Here is my button search event…

protected void btnSearch_Click(object sender, System.EventArgs e)


SearchText = txtSearch.Text; //getting text to be searched from text box.

fillDataGrid(); //populating data grid..


Key press event…..

private void txtSearch_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)


if(e.KeyChar == (char) 13)


this.btnSearch_Click(sender, new EventArgs());



can any one say the solution...?

Thanks in advance..
May 11 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.