views:

410

answers:

1

Hi there,

I have a ListView inside a FormView that, for some strange reason, doesn't fire neither the ItemInsert nor the ItemCommand event. I'm populating the ListView with a generic list. I bind the list to the ListView on the OnPreRenderComplete.

    <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>   

My ItemDataBound method is:

    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);
        }
    }

So, basically, in the InsertItemTemplate I put a button that opens a LOV and populates my valRef and txtRef fields. I had to put a "return false" in order for the parent page to not postback (and I think the problem lies here...). Then, when I click in the ImageButton with the CommandName="Insert", instead of firing the ItemCommand event, it enters once again in the ItemDataBound handler.

So, any ideas?

Thanks!

A: 

Well, after searching for a few days, I found out this is a known bug. http://connect.microsoft.com/VisualStudio/feedback/details/328680/problem-accessing-controls-clientid-on-asp-net-listviews-itemcreated

So, it hasn't nothing to do with the popup, but with the ListView and the ItemDataBound itself. I put the ItemDataBound logic on the OnLoad (using a recursive FindControl), and it worked. So, in the ItemDataBound, the ClientID of my controls is "wrong". Stupid bug really...

nevizi