2013-04-27 120 views
1

我只是想在具有OnItemCommand的中繼器中觸發LinkBut​​ton。但是頁面會回傳。這裏是我的代碼:updatepanel不會觸發中繼器itemcommand

<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 could'nt找到

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

我已經研究了很多的文件寫這個問題,但我找不到有用的例子和解決方案。

最好的問候。

回答

0

嘗試將ClientIDMode =「AutoID」添加到@page指令

相關問題