gpt4 book ai didi

asp.net - 如何访问 ASP.net 中嵌套中继器内的按钮?

转载 作者:行者123 更新时间:2023-12-02 03:14:37 24 4
gpt4 key购买 nike

我一直在努力了解发生了什么,但我在网上搜索无济于事。

如何访问嵌套中继器内的按钮?我花了很多时间研究/试验,但我不明白发生了什么。

HTML 标记:

<asp:Repeater runat="server" ID="repQuestionTopics">
....
<asp:Repeater ID="repQA" runat="server">
....
<strong>Was this article helpful?</strong>&nbsp;
<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 端输入函数:

<button class="button tiny secondary radius" runat="server" OnClick="repTopics_ItemCommand"
CommandName="voteYes" id="btnVoteHelpfulYes">Yes</button>

当单击按钮 voteYes 时,我希望能够转到数据库并更新计数器,以便我可以跟踪该答案的赞成票和反对票的数量问题。

无论我实现什么更改来尝试让它工作,当我单击按钮时,页面都会刷新,仅此而已 - 没有别的。

最佳答案

HTML 标记:您必须将 OnItemCommand 事件添加到内部 Repeater repAQ:

<asp:Repeater ID="repQA" runat="server" OnItemCommand="repQA_ItemCommand">

代码隐藏:

VB.Net:

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

ASP.Net:

protected void repQA_ItemCommand(object source, RepeaterCommandEventArgs e)
{
// check for right name of command
if(e.CommandName == "voteYes")
{
....
}
}

关于asp.net - 如何访问 ASP.net 中嵌套中继器内的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37792258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com