Using VS2013 I'm creating a website to collect some data on a tablet (using IE). I don't want to use the tablet keyboard so I created a numberpad out of asp buttons instead. I need to know which textbox had focus in order to change the text to the value of the button clicked.
Here's my problem - the textbox is dynamically created inside a gridview template field that is also dynamically created when each row is databound. So the field and the controls don't exist in the aspx page.
I can't figure out how to determine which textbox is selected before the button is clicked. I believe this needs to be done client side using js or jquery, but I have never used these before.
I need a script that inserts the clicked number into the textbox that was most recently selected.
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If (Not IsPostBack) Then tfield = New TemplateField() tfield.HeaderText = "Count" GridView1.Columns.Add(tfield) Dim GhostTable As New DataTable GhostTable.Columns.Add(New DataColumn("Count")) 'Initialize table with 1 blank row Dim blankRow As DataRow = GhostTable.NewRow() GhostTable.Rows.Add(blankRow) 'Makes the gridview reflect the GhostTable (currently 1 blank row) GridView1.DataSource = GhostTable GridView1.DataBind() Else 'Occurs on every postback GridView1.DataSource = Session("GhostTable") GridView1.DataBind() End If End Sub Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound 'Handles databinding of each gridview1 row and adds the textboxes to the template fields If e.Row.RowType = DataControlRowType.DataRow Then Dim tbxCount As New TextBox() tbxCount.ID = "tbxCount" tbxCount.Text = TryCast(e.Row.DataItem, DataRowView).Row.Item("Count").ToString() tbxCount.Width = 100 tbxCount.Height = 61 tbxCount.Font.Size = 36 e.Row.Cells(5).Controls.Add(tbxCount) End if End sub Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'Determine which of the gridview row's "tbxCount" was focused and insert the number 1 'preferably this would happen on the client side? End Sub
Sorry this was so long everyone. Just wanted to make sure I provided enough information.