I have problems with a form in ASP.net in VB, this form created dynamic texboxes and I have a button to add the textboxes. Now this button when adding the new textbox row saves what has a row before in the DB. Now the question is how can I make it so that when I press the "Enter" key, it executes the onclick event of my button. I tried the DefaultButton property but it only works when the page is refreshed, after clicking on another part of the interface it stops working. I've seen that it can be recognized when the "Enter" key is pressed from javascript, but I don't know how to execute the event code.
That is the code that I have in the botton the name of the event is "AddTextBox" in the Onclick event
<asp:Button ID="btnAdd" runat="server" Text="Add and Save "
OnClick="AddTextBox" />
This would be the CodeBing that contains this button
Protected Sub AddTextBox(sender As Object, e As EventArgs)
'primer panel'
Dim index As Integer = PNLNoNotes.Controls.OfType(Of TextBox)().ToList().Count + 1 'crea una lista que contendra los nombres de los txt dinamicos de panel 1
Me.CreateTextBox("txtPnl1" & index) 'txtPnl1 es el nombre de los txt del panel 1
For Each textBox As TextBox In PNLNoNotes.Controls.OfType(Of TextBox)()
If (textBox.ID = "txtPnl1" + Convert.ToString(index)) Then
textBox.Text = index
algo = index
End If
Next
RecuperarDatos(index)
end sub
Ok now I need to know how I can 1st, detect when the "Enter" key is pressed and secondly know how to call or execute this event when the "Enter" key is pressed
If you want to execute the "click" event of your "button" when pressing enter inside your "textbox":
In both, only change the selector #txtPnl1 if the id of your textbox is something else, and the selector #btnAdd if the id of your button is something else.