如何在ASP.net中访问嵌套中继器内的按钮?
我一直试图了解正在发生的事情,但我在网上搜索却毫无结果 如何访问嵌套中继器内的按钮?我花了这么多时间研究/实验,我不明白发生了什么如何在ASP.net中访问嵌套中继器内的按钮?,asp.net,button,nested,repeater,Asp.net,Button,Nested,Repeater,我一直试图了解正在发生的事情,但我在网上搜索却毫无结果 如何访问嵌套中继器内的按钮?我花了这么多时间研究/实验,我不明白发生了什么 HTML标记: <asp:Repeater runat="server" ID="repQuestionTopics"> .... <asp:Repeater ID="repQA" runat="server"> .... <strong>Was this article helpf
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
?出于某种原因,我的代码隐藏不允许我编写函数Handles repQA.ItemCommand-为什么?我曾尝试使用类似(添加OnClick)的方法在asp端直接输入函数:
是
单击按钮voteYes
时,我希望能够转到数据库并更新计数器,以便跟踪该问题答案的赞成票和反对票数量
无论我执行了什么更改,当我单击按钮时,页面都会刷新,仅此而已。HTML标记:您必须将
OnItemCommand
事件添加到内部中继器repAQ
:
<asp:Repeater ID="repQA" runat="server" OnItemCommand="repQA_ItemCommand">
ASP.Net:
<asp:Repeater ID="repQA" runat="server" OnItemCommand="repQA_ItemCommand">
Public Sub repQA_ItemCommand(Sender As Object, e As RepeaterCommandEventArgs)
// check for right name of command
If e.CommandName = "voteYes" Then
....
End If
End Sub
protected void repQA_ItemCommand(object source, RepeaterCommandEventArgs e)
{
// check for right name of command
if(e.CommandName == "voteYes")
{
....
}
}