我有我創建後面代碼訪問控制以JavaScript
Dim txtdate1 As New TextBox
txtdate1.ID = "txtdate1"
cell.Controls.Add(txtdate1)
細胞爲i添加到一個gridview一個標題表單元格的控制。
我需要訪問這個在JavaScript
var txtdate1 = document.getElementById('txtdate1');
OR
var txtdate1 = document.getElementById('<%=txtdate1.clientID');
如何才能做到這一點?
這是細胞如何創建
Dim cell As New TableCell
Dim row As New GridViewRow(-1, -1, DataControlRowType.Separator, DataControlRowState.Normal)
row.BackColor = System.Drawing.ColorTranslator.FromHtml("#B5C7DE")
row.ForeColor = Drawing.Color.White
If GridView1.Rows.Count <> 0 Then
GridView1.Rows(0).Parent.Controls.AddAt(0, row)
Else
End If
row.Controls.Add(labelcell)
row.Cells.Add(cell)
我收到以下內容: 名稱'txtdate1'未聲明 – Eric 2009-08-12 16:27:51
錯誤是正確的,因爲控件未在頁面上聲明。你在這裏處理動態控制,所以你需要做一個動態查找。 – Yona 2009-08-12 16:38:47
@Y Low-如何在這種情況下使用動態查找?我從來沒有聽說過它。 – Eric 2009-08-12 16:47:03