asp.net - Repeater 和 UpdatePanel 在命令上更改按钮背景色
问题描述
我有一个带有中继器控件的更新面板,里面有按钮。我想在用户按下按钮时更改背景颜色。目前,该命令执行良好,但颜色没有改变。这是aspx文件。
<asp:UpdatePanel ID="updDocumentQuickView" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<asp:Button ID="Button1" CssClass="wrap" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "productName")%>' ForeColor="White" BorderColor="#b0003a" BackColor="#e91e63" Width="100" Height="100" Style="border-radius: 8px;" Font-Size="Medium" />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
后面的代码是
Protected Sub Repeater1_ItemCommand(source As Object, e As RepeaterCommandEventArgs)
Dim btn1 As Button = CType(e.Item.FindControl("Button1"), Button)
btn1.BackColor = Drawing.Color.Black
end sub
但颜色没有变化
你还有别的事吗?
解决方案
由于您UpdatePanel
使用UpdateMode="Conditional"
and定义了您ChildrenAsTriggers="false"
的面板,因此在您Update
在后面的代码中调用该方法或为UpdatePanel
.
有关更多信息,请参阅此资源。
推荐阅读
- c# - 我可以在 Windows 窗体窗体中创建和显示多少个控件?
- .net - 无法在 COM 对象中创建 SSL/TLS 安全通道
- api - 在 Kong API 网关后面保护微服务 API
- sql - PostgreSQL:评估函数内部的子字符串
- android - Gradle 项目同步在导入另一个模块时失败
- ffmpeg - 消除 ffmpeg 和 image-magic 命令中的慢速因素
- html - 从 .NET 打印 html 文档
- bash - 如何在 BASH 脚本中的 [[:space:]] && '(' 之后截断?
- php - 正则表达式 Preg 替换 HTML
- python - 字符串的 ISO 时间转换(条件为当地时间 2018 年 10 月 23 日 09:18)