首页 > 解决方案 > 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

但颜色没有变化

你还有别的事吗?

标签: asp.net

解决方案


由于您UpdatePanel使用UpdateMode="Conditional"and定义了您ChildrenAsTriggers="false"的面板,因此在您Update在后面的代码中调用该方法或为UpdatePanel.

有关更多信息,请参阅此资源


推荐阅读