Click here to Skip to main content
15,908,841 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please explain the Textbox Keydown event in windows application.

For example if i click the enter key it will open the new UI.
Posted
Updated 4-Nov-11 20:54pm
v4
Comments
koolprasad2003 5-Nov-11 2:36am    
You need Window or webbased application ?
in your Tag you have given "ASP.NET" and in your question you wrote "window based".
please explain in detail
Sam Path 5-Nov-11 2:38am    
Sorry Windows Application..
Tejas Vaishnav 5-Nov-11 2:54am    
Provide Proper Tag for your question...
Sam Path 5-Nov-11 2:56am    
ok Sir sorry...

In webbased application ?
You need to take help of Javascript. write a function in javascript and call it on keypress event of textbox. here is example.

.aspx page
C#
<asp:textbox id="txtsubmit" runat="server" onkeypress="return callME()" xmlns:asp="#unknown" />


Javascript function.
JavaScript
function CalllME()
{
  if(event.keyCode == 13) //enter Keycode is 13
  {
     window.open(//Open new UI);
     return false;
  }
}
 
Share this answer
 
v2
Comments
koolprasad2003 5-Nov-11 2:42am    
check my below answer
RaviRanjanKr 5-Nov-11 2:47am    
My 5+
Add a handler for your TextBox's KeyDown event. (This assumes you set the AcceptsReturn property to False). Then in your KeyDown eventhandler, have code such as:

C#
if (e.KeyCode = Keys.Enter)
          window.open();//code to open your UI


Also refer this link:

http://www.dotnetperls.com/keycode[^]
 
Share this answer
 
v2
Comments
RaviRanjanKr 5-Nov-11 2:47am    
My 5+
sravani.v 5-Nov-11 3:18am    
Thank you....
There is event of Keydown for textbox. use to check if enter is pressed.
VB
Private void txtbrowse_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles btnBrowse.KeyDown
{
     if (e.KeyData = Keys.Enter)
     {
          //open new UI
     }
}
 
Share this answer
 
And also use a visual studios property window and there is one option to show all events attached to text box...

just select any event which you want and double click on it, it will automatically generate that event for you.....

OR use this syntax to generate event of any controll


C#
yourcontrolID.youreventtogenerate += .. press two times tab key it will genrate that event fro you...

LIKE

TextBox1.TextChanged += TAB + TAB .......PRESS TAB KEY TWO TIMES

then it will generate like this...

RESULT IN....

TextBox1.TextChanged += new EventHandler(TextBox1_TextChanged);

void TextBox1_TextChanged(object sender, EventArgs e)
{
    throw new NotImplementedException();
}


Now copy that event name from genrated method and as per event modify your design code fro attaching that event to your text box... or any control...


For more detail on events please see this...
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.aspx[^]
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox_events.aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900