471,592 Members | 1,149 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,592 software developers and data experts.

How to activate button click event using enter button


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
0 1882

Post your reply

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

Similar topics

3 posts views Thread by Philip Townsend | last post: by
5 posts views Thread by Steve | last post: by
6 posts views Thread by Michael Johnson Jr. | last post: by
1 post views Thread by marcelo | last post: by
3 posts views Thread by Imran Aziz | last post: by
2 posts views Thread by carmelo.orlando | last post: by
3 posts views Thread by Robert W. | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.