2010-06-08 22 views
1

我有一個FormView內部的ListView,出於某種奇怪的原因,它既不觸發ItemInsert也不觸發ItemCommand事件。 我正在使用通用列表填充ListView。我將列表綁定到OnPreRenderComplete上的ListView。ListView在防止回傳後沒有觸發OnItemCommand(也沒有ItemInserting)

<asp:ListView runat="server" ID="lvReferences" DataKeyNames="idReference" OnItemInserting="ContractReferences_Inserting" OnItemDeleting="ContractReferences_Deleting" InsertItemPosition="LastItem" OnItemCommand="ContractReferences_Command" OnItemCreated="ContractReferences_ItemDataBound">          
    <LayoutTemplate> 
     <ul>  
       <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> 
     </ul>         
    </LayoutTemplate> 
    <ItemTemplate> 
     <li class="obsItem"> 
      <a href="#"><asp:TextBox ID="valRef" runat="server" Width="5px" Enabled="false" Text='<%#Bind("idProcessRecordRef") %>' /></a>          
      <asp:TextBox id="txtRef" runat="server" Text='<%#Bind("description") %>' /> 
      <asp:ImageButton ID="btDelete" runat="server" CommandName="Delete" ImageUrl="~/_layouts/web.commons/Images/eliminar.png" /> 
     </li> 
    </ItemTemplate> 
    <InsertItemTemplate> 
     <li class="obsItem"> 
      <a href="#"><asp:TextBox ID="valRef" runat="server" Width="5px" Enabled="false" /></a>          
      <asp:TextBox id="txtRef" runat="server" /> 
      <asp:ImageButton ID="btDetail" CausesValidation="false" OnClientClick="javascript:openPopup();return false;" runat="server" ImageUrl="~/_layouts/web.commons/Images/novo.png" /> 
      <asp:ImageButton ID="btSaveDs" runat="server" CommmandName="Insert" CausesValidation="false" ImageUrl="~/_layouts/web.commons/Images/gravarObs.png" /> 
     </li> 
    </InsertItemTemplate> 
</asp:ListView> 

我的ItemDataBound方法是:

protected void ContractReferences_ItemDataBound(object sender, ListViewItemEventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      TextBox valRef = e.Item.FindControl("valRef") as TextBox; 
      TextBox txtRef = e.Item.FindControl("txtRef") as TextBox; 
      ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "function openPopup(){ window.open('ContractPicker.aspx?c1=" + valRef.ClientID + "&c2=" + txtRef.ClientID + "');}", true); 
     } 
    } 

所以,基本上,在InsertTemplate則我將打開一個LOV和填充我的valRef和txtRef領域的一個按鈕。爲了讓父頁不回發,我必須輸入「return false」(並且我認爲問題在於...)。 然後,當我用CommandName =「Insert」單擊ImageButton時,不是觸發ItemCommand事件,而是再次進入ItemDataBound處理程序。

那麼,有什麼想法?

謝謝!

+0

btw,建立複雜的字符串建議嘗試'String.Format()' – abatishchev 2010-06-08 17:48:08

+0

是的我知道,我得到一個討厭的錯誤使用String.Format,因爲我浪費了很多與此同時,我建立了連接字符串,直到我解決了這個錯誤。 – nevizi 2010-06-08 17:52:29

回答

1

好吧,搜索幾天後,我發現這是一個已知的錯誤。 http://connect.microsoft.com/VisualStudio/feedback/details/328680/problem-accessing-controls-clientid-on-asp-net-listviews-itemcreated

因此,它與彈出窗口無關,但是與ListView和ItemDataBound本身無關。我把ItemDataBound邏輯放在OnLoad上(使用遞歸的FindControl),並且它工作。 因此,在ItemDataBound中,我的控件的ClientID是「錯誤的」。 愚蠢的錯誤真的...

相關問題