Hi,
I have a GridView with a delete Button on each line, to delete that row. This works fine usingCommandName="Delete" propertyon the button and theRowDeleting Event on the GridView.
What I want is to use the ModalPopup to make a delete confirmation, but, I can't put this to work. The RowDeleting Event doen's work anymore.
What should I do?
This is the code:
<ItemTemplate> <asp:ImageButton ID="ibDelete" runat="server" CausesValidation="False" CommandName="Delete" ImageUrl="../../UserFiles/Images/ico_del.gif" ToolTip="delete row"/> <asp:Panel ID="pnlPopUp" runat="server" Style="display: none" CssClass="modalPopup"> <asp:Panel ID="pnlDragPopUp" runat="server" Style="cursor: move;background-color:#DDDDDD;border:solid 1px Gray;color:Black"> <div> <p>Are you sure you want to delete this item?</p> </div> </asp:Panel> <div> <p style="text-align: center;"> <asp:Button ID="OkButton" runat="server" Text="Yes" /> <asp:Button ID="CancelButton" runat="server" Text="Cancel" /> </p> </div> </asp:Panel> <ajax:ModalPopupExtender ID="ModalPopupExtender" runat="server" TargetControlID="ibDelete" PopupControlID="pnlPopUp" BackgroundCssClass="modalBackground" OkControlID="OkButton" CancelControlID="CancelButton" DropShadow="true" PopupDragHandleControlID="pnlDragPopUp" /> </ItemTemplate>
The GridView Event:
Protected Sub MyGridView_RowDeleting(ByVal senderAs Object,ByVal eAs GridViewDeleteEventArgs)Dim myConnetionAs SqlConnection =New SqlConnection(erpConn)Dim delCommandAs SqlCommand = myConnetion.CreateCommand() delCommand.CommandText ="myQuery" delCommand.Parameters.Add("@dotnet.itags.org.Adress", SqlDbType.NVarChar).Value = MyGridView.DataKeys(e.RowIndex).Values(0).ToString() myConnetion.Open() delCommand.ExecuteNonQuery() myConnetion.Close() GetUser()End Sub
Anyone?
Hi Cseven,
Would you please remove theOkControlID="OkButton"
<ajax:ModalPopupExtender ID="ModalPopupExtender" runat="server"
TargetControlID="ibDelete"
PopupControlID="pnlPopUp"
BackgroundCssClass="modalBackground"
OkControlID="OkButton" //remove this item
CancelControlID="CancelButton"
DropShadow="true"
PopupDragHandleControlID="pnlDragPopUp" />
In your case, it won't post back, so that's cause the problem.
By the way, in your case , there are severalModalPopupExtenders and Panels in a page. It is cool but not an efficient way.
I hope this help.
Best regards,
Jonathan
the modalpopupextender takes control of its targetcontrol...so in your case the ibDelete button event, which fires the RowDeleting, is being overridden on the client
you have two options:
1) use the old hidden button hack and show your modalpopup programatically. Place another button right above your modalpopupextender and hide it via css...then set your modalpopupextender targetcontrolid to that button... now in your code-behind inside your gridview_rowcommand event...put a logic statement checking e.commandname ...if it equals "Delete" then call ModalPopupExtender.Show()...
2) create a webmethod that deletes the row manually and call it with the onokscript via the modalpopupextender
No comments:
Post a Comment