2
我一直在試圖瞭解發生了什麼,並且我在網上搜索無濟於事。如何訪問ASP.net中嵌套中繼器內的按鈕?
如何訪問嵌套中繼器內的按鈕?我花了很多時間研究/試驗,我不明白髮生了什麼。
HTML標記:
<asp:Repeater runat="server" ID="repQuestionTopics">
....
<asp:Repeater ID="repQA" runat="server">
....
<strong>Was this article helpful?</strong>
<button class="button tiny secondary radius" runat="server"
CommandName="voteYes" id="btnVoteHelpfulYes">Yes</button>
<button class="button tiny secondary radius" runat="server"
CommandName="voteNo" ID="btnVoteHelpfulNo">No</button>
</asp:Repeater>
</asp:Repeater>
代碼隱藏:
//Handles repQuestionTopics.ItemCommand
Public Sub repTopics_ItemCommand(Sender As Object, e As RepeaterCommandEventArgs)
If e.CommandName = "voteYes" Then
....
End If
End Sub
如何獲得對repQA
訪問?出於某種原因,我的代碼不會讓我寫功能處理repQA.ItemCommand - 爲什麼?我曾嘗試直接輸入使用類似(添加的OnClick)上的ASP方面的功能:
<button class="button tiny secondary radius" runat="server" OnClick="repTopics_ItemCommand"
CommandName="voteYes" id="btnVoteHelpfulYes">Yes</button>
當按鈕voteYes
點擊我希望能夠去到數據庫並更新計數器,所以我可以跟蹤該問題的答案有多少票和反對票。
無論我實施什麼樣的變化,當我點擊按鈕來嘗試並使其工作,頁面刷新,就是這樣 - 沒有別的。