ListView not firing OnItemCommand (nor ItemInserting) after preventing postback
Posted
by nevizi
on Stack Overflow
See other posts from Stack Overflow
or by nevizi
Published on 2010-06-08T17:44:44Z
Indexed on
2010/06/15
11:32 UTC
Read the original article
Hit count: 531
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!
© Stack Overflow or respective owner