updatepanel不会触发repeater itemcommand

时间:2013-04-27 21:33:15

标签: updatepanel repeater linkbutton itemcommand

我只想在具有OnItemCommand的转发器中触发LinkBut​​ton。但该页面会回发。这是我的代码:

<asp:UpdatePanel ID="recommendedAdvertsUpPnl" runat="server">
    <ContentTemplate>
        <div class="tagList">       
            <asp:Label ID="lbListBookType" runat="server"></asp:Label>
            <asp:Repeater ID="rpRecommendedAdvertFacultyList" runat="server" OnItemDataBound="rpRecommendedAdvertFacultyList_ItemDataBound" OnItemCommand="rpRecommendedAdvertFacultyList_ItemCommand">
                <HeaderTemplate></HeaderTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="lbtnAdvertFaculty" runat="server" CommandArgument='<%#Eval("facultyId") %>' CommandName="selectFaculty" CssClass="advertFacultySelection"></asp:LinkButton>
                </ItemTemplate>
                <FooterTemplate></FooterTemplate>
            </asp:Repeater>        
        </div>
    <div class="RecommendedAdverts_List">
    <asp:Repeater ID="rpRecommendedAdvertList" runat="server" OnItemDataBound="rpRecommendedAdvertList_ItemDataBound">
        <HeaderTemplate>
            <ul class="content_recommended">
        </HeaderTemplate>
        <ItemTemplate>
            <%# Container.ItemIndex % 4 == 0  ? "<li><div class=advertContainer>": String.Empty%>
            <div class="advertPanel">
                <div class="rAdvPanel">
                    <div class="advertPic"><asp:Panel ID="pnlRecAdvertPic" runat="server"></asp:Panel></div>
                    <div class="advertInfoPanel">
                        <a href="../../IlanDetay/<%#Eval("Book.name") %>/<%#Eval("id") %>"><%#Eval("Book.Name")%></a> <br />
                        <%#Eval("Book.Authors")%><br />
                        <%#Eval("Price")%> TL<br />
                    </div>
                </div>
            </div>
        <%# Container.ItemIndex % 4 == 3 ? "</div></li>": String.Empty%>
        </ItemTemplate>
        <FooterTemplate>
                </div></li>
            </ul>
        </FooterTemplate>
    </asp:Repeater>
    </div>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="rpRecommendedAdvertFacultyList" EventName="ItemCommand" />
    </Triggers>

</asp:UpdatePanel>

除了触发之外没有问题。这是我的服务器端代码:

protected void rpRecommendedAdvertFacultyList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
    {
        AdvertFacultyInfo item = (AdvertFacultyInfo)e.Item.DataItem;
        LinkButton lbtnAdvertFaculty = (LinkButton)e.Item.FindControl("lbtnAdvertFaculty");

        lbtnAdvertFaculty.Text = item.Faculty.name;            
    }
}

protected void rpRecommendedAdvertFacultyList_ItemCommand(object source, RepeaterCommandEventArgs e)
{        
    switch (e.CommandName)
    {
        case "selectFaculty":
            List<AdvertFacultyInfo> advFacultyInfoList = EntitiyProvider.GetAdvertFacultyInfoListByFacultyId(Convert.ToInt32(e.CommandArgument));
            List<Advert> selectedList = new List<Advert>();
            foreach (AdvertFacultyInfo item in advFacultyInfoList)
            {
                Advert currentAdv = this.recommendedAdvertList.FirstOrDefault(i => i.id == item.advertId);
                if ( currentAdv != null)
                {
                    selectedList.Add(currentAdv);
                }
            }
            rpRecommendedAdvertList.DataSource = selectedList;
            rpRecommendedAdvertList.DataBind();

            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script type='text/javascript'>$('.content_recommended').quickPager()</script>", false);
            break;

        default:
            break;
    }
}

我也尝试过这段代码:但是它提供的错误就像 lbtnAdvertFaculty 找不到

<asp:AsyncPostBackTrigger ControlID="lbtnAdvertFaculty" EventName="Click" />

我已经研究了很多关于这个问题的文档,但我找不到有用的例子和解决方案。

最诚挚的问候。

1 个答案:

答案 0 :(得分:0)

尝试将ClientIDMode =“AutoID”放到@page指令