防止回发后的ListView不点火OnItemCommand(也不ItemInserting)(Li

2019-10-22 22:05发布

我有,一些奇怪的原因,不火都不ItemInsert也不ItemCommand事件一个FormView内的ListView。 我用填充泛型列表ListView控件。 我的列表结合于OnPreRenderComplete ListView控件。

    <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领域的一个按钮。 我不得不把为了一个“返回false”父页面不回传(我认为问题就出在这里...)。 然后,当我点击,而不是射击ItemCommand事件与的CommandName =“插入”中的ImageButton,它在处理器的ItemDataBound再次进入。

因此,任何想法?

谢谢!

Answer 1:

那么,寻找了几天后,我发现这是一个已知的bug。 http://connect.microsoft.com/VisualStudio/feedback/details/328680/problem-accessing-controls-clientid-on-asp-net-listviews-itemcreated

因此,它不是无关弹出,但使用ListView和自身的ItemDataBound。 我把在onload(使用递归的FindControl)中的ItemDataBound逻辑,和它的工作。 所以,在的ItemDataBound,我控制的客户端ID是“错误的”。 愚蠢的错误真的...



文章来源: ListView not firing OnItemCommand (nor ItemInserting) after preventing postback