下面是我要顯示的目錄的代碼。我正確地從數據庫中獲取內容以顯示在網頁上。我已將關於從數據庫獲取的內容的鏈接按鈕添加到表中。我不知道爲什麼,linkbutton不會觸發添加到它的事件。有誰能告訴我爲什麼和什麼原因導致事件不能開火?Linkbutton onclick事件不會在VB.Net中的UpdatePanel內部觸發
ASPX:
<form id="myForm" runat="server">
<asp:ScriptManager runat="server" ID="spm1" />
<asp:UpdatePanel runat="server" ID="up1">
<ContentTemplate>
<table runat="server" id="doctorList" class="mel-table" style="text- align:center">
<tr>
<td class="mel-table-header">Doctor Code</td>
<td class="mel-table-header">First Name</td>
<td class="mel-table-header">Last Name</td>
<td class="mel-table-header">Is Active?</td>
<td class="mel-table-header">Update</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</form>
ASPX.VB:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim content As String = ""
If Not IsPostBack Then
Dim docBOs As List(Of BO_Doctors) = docList.getDoctors()
// This brings the Doctors List from Database properly
For Each docB As BO_Doctors In docBOs
Dim tr As New HtmlTableRow
Dim td1 As New HtmlTableCell
td1.InnerText = docB.docCode
tr.Cells.Add(td1)
Dim td2 As New HtmlTableCell
td2.InnerText = docB.docfName
tr.Cells.Add(td2)
Dim td3 As New HtmlTableCell
td3.InnerText = docB.doclName
tr.Cells.Add(td3)
Dim td4 As New HtmlTableCell
td4.InnerText = docB.isActive
tr.Cells.Add(td4)
Dim td5 As New HtmlTableCell
Dim editBtn As New LinkButton
editBtn.Text = "Edit"
editBtn.ID = docB.docCode
AddHandler editBtn.Click, AddressOf editBtn_Click
td5.Controls.Add(editBtn)
tr.Cells.Add(td5)
doctorList.Rows.Add(tr)
Next
End If
End Sub
Protected Sub editBtn_Click(sender As Object, e As EventArgs)
Dim btn As LinkButton = CType(sender, LinkButton)
Dim doc As BO_Doctors = docList.getaDoctor(btn.ID)
End Sub
上面提到的LinkButton在哪裏? – wooer
linkbutton在運行時生成。 –
然後你需要添加鏈接按鈕後在運行時將它作爲AsyncPostBackTrigger添加.. – wooer