vrao92
asked on
Command Button click when enter key is pressed
I have a webform(vb.net) and it has a grid control with 2 button in item template(edit,delete).
I also have 2 command button outside the gridview. One is to add a new row in gridview and the other is to "return to a previous webpage". I want the "return to previous page" click event to be fired when the user presses "enter key".
How do I do that?
Thanks
I also have 2 command button outside the gridview. One is to add a new row in gridview and the other is to "return to a previous webpage". I want the "return to previous page" click event to be fired when the user presses "enter key".
How do I do that?
Thanks
I could clearly understand your requirements. Do you wish that the button to go to previous page be activated when the Enter is pressed on this button (and mouse clicking be disabled for this button) OR Enter is pressed anywhere on the page?
ASKER
Yes..exactly..how Do I do that?
Correction to above: I could not clearly understand your requirements.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Say your Grid Control is Grid1 and the Command Button
outside your grid is Command1. Add this code to the
grids keypress event
Private Sub Grid1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Command1_Click
End Sub
outside your grid is Command1. Add this code to the
grids keypress event
Private Sub Grid1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Command1_Click
End Sub
ASKER
The grid ,button and all teh controls are in a Content control called content1.
Will the content can be set as default button?
Thanks
Will the content can be set as default button?
Thanks
ASKER
I am using vb.net.
You should try my solution. It is very easy.
in the Page_Load ... set the default button property of your Form like this:
form1.DefaultButton = "Button1";
form1 === ID of your form element
"Button1" === ID of your Button that takes your to pervious page.
form1.DefaultButton = "Button1";
form1 === ID of your form element
"Button1" === ID of your Button that takes your to pervious page.
sorry VB won't have ; at the end of statement...
form1.DefaultButton = "Button1"
form1.DefaultButton = "Button1"
ASKER
Hehdaddy.. I tried creating a pael and I have placed the grid control and the command button inside the panela nd tried your code. It is still not working.
ASKER
guru_sami:
I have one master page and several pages underneath that. This is one of the page and in this page I have a gridview and a button.
I do not see DefaultButton property? where should I see that?
I have one master page and several pages underneath that. This is one of the page and in this page I have a gridview and a button.
I do not see DefaultButton property? where should I see that?
There might be a better way but one I could get is in code below.
Pag Load of your content Page you set the default button and default focus of your Button.
Pag Load of your content Page you set the default button and default focus of your Button.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Form.DefaultButton = Button1.UniqueID
Form.DefaultFocus = Button1.ClientID
End Sub
When I asked explanation above of your requirements, you did not come with a clear answer. I am still confused if:
You wish to restrict the user on the client side so he/she would not be able to click the button with mouse or press any key other than Enter. So the button for "return to previous page" will submit the request to server (click event fired on server side ASP.NET code) only when the Enter key is pressed on that button.
OR
You wish that whenever Enter key is pressed anywhere in any control of the page, the button for "return to previous page" be pressed that will ultimately submit the request to the server (click event fired on server side ASP.NET code).
If any one of the above is actually your requirement, it is more of a JavaScript job rather than server-side ASP.NET although you might have to set the JavaScript code from within the ASP.NET code. Let me know if it is what you wish to have, and I may be able to post some sample code/references to solve your problem.
You wish to restrict the user on the client side so he/she would not be able to click the button with mouse or press any key other than Enter. So the button for "return to previous page" will submit the request to server (click event fired on server side ASP.NET code) only when the Enter key is pressed on that button.
OR
You wish that whenever Enter key is pressed anywhere in any control of the page, the button for "return to previous page" be pressed that will ultimately submit the request to the server (click event fired on server side ASP.NET code).
If any one of the above is actually your requirement, it is more of a JavaScript job rather than server-side ASP.NET although you might have to set the JavaScript code from within the ASP.NET code. Let me know if it is what you wish to have, and I may be able to post some sample code/references to solve your problem.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
moghazali:
I am sorry My post is not clear.
I need this to happen..
whenever Enter key is pressed anywhere in any control of the page, the button for "return to previous page" be pressed that will ultimately submit the request to the server (click event fired on server side ASP.NET code).
Thanks again
commandButtonProblem.txt
I am sorry My post is not clear.
I need this to happen..
whenever Enter key is pressed anywhere in any control of the page, the button for "return to previous page" be pressed that will ultimately submit the request to the server (click event fired on server side ASP.NET code).
Thanks again
commandButtonProblem.txt
Hey vrao92,
Did you try my code? It will work whenever Enter key is pressed anywhere on the page.
Baiju
Did you try my code? It will work whenever Enter key is pressed anywhere on the page.
Baiju
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.