1

我只想在具有 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" />

我研究了很多有关此问题的文档,但找不到有用的示例和解决方案。

此致。

4

1 回答 1

0

尝试将 ClientIDMode="AutoID" 放入 @page 指令

于 2015-04-10T19:58:09.377 回答