Hi,
I have an UltraWebGrid with a column "Delete", column type = Infragistics.WebUI.UltraWebGrid.ColumnType.Button. When the user clicks in the button, I delete the row (from DB, so it is server side). I want to add a confirmation message to ask to the user for confirmation before deleting the row. I want to do it in the client-side. I tried using AJAX but I didn't find the way to use it in UltraWebGrid. Also, I tried using the DisplayLayout.ClientSideEvents.CellClickHandler and others properties but I couldn't solve my problem.
(Note: I have the UltraWebGrid inside a WebAsyncRefreshPanel)
Thanks
Regards,Fernando
The easiest way would be to add a confirm message to your button click event handler on the client-side. Basically cancel the button-click if !confirm("are you sure you want to delete this row").
Posting back and forth the the server to accomplish this is a bit more complicated. It also causes some unnecesary traffic so it may effect server performance. But if you really must handle this on the server, you can use the before row deleted event on the serverside. Cancel the event so that the grid does not perform the delete. Instead, make a panel visible which asks about the delete and has 2 buttons. You should encode the row id into the commandtext for the button, and then on the button event delete the appropriate row.
-Tony
First: thank you very much for your help.
[
]
That is just what I want. But: where is the "button click event handler"? If I use only one button for all the grid, selecting a row before deleting, I can add that confirmation, but in this case the button is a button per row. This is, I change the Column.Type in the Grid.InitializeLayout event, so how can I add a button click event handler to that button (really: many buttons, one per row)?For instance, I have:Protected Sub UltraWebGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.LayoutEventArgs) Handles UltraWebGrid1.InitializeLayout
col = Utils.GetGridCol(UltraWebGrid1, "Remove") col.Header.Caption = "Remove" col.Type = Infragistics.WebUI.UltraWebGrid.ColumnType.Button col.AllowUpdate = Infragistics.WebUI.UltraWebGrid.AllowUpdate.Yes
End If
End Sub And I need the event handler to this "button column"
Thanks -Fernando
You should be able to use the ClickCellButton client-side event
Fired when a cell's button is clicked on the client.
String. The name of the Grid which is firing this event.
String. The id of the cell whose button was clicked.
This event will be fired when the button is clicked on the client-side. In the event handler, try this code-
function CellClick(gn,cid){ if(!confirm("are you sure you want to delete..")) igtbl_cancelPostBack(gn);}
That should prompt the user with a confirm box, and prevent the postback from occuring if the user clicks cancel.
Tony
Can u supply an example of aspx code that declares or "tells" this event to occur?
I am using a C# code behind page. I have the postback event handler set up. That works and postback occurs until I try to implement this js confirmation function. Now the js runs, but the postback never occurs, even if the user answers OK to the prompt. Here is what I tryed to do on the aspx page to get this to work:
<ClientSideEvents ClickCellButtonHandler="CellClick()"> </ClientSideEvents>
Also, I do not understand how I could place the cellid in the function call, as every row has a different cellid at run time, doesnt it?
Jeff
Jeff,
client-side event handlers should be defined as the function name only. In your case above, I think including parenthesis is what's messing up the event firing. Set ClickCellButtonHandler="CellClick", and then define
function CellClick(gridname,cellid){//insert code here}
the grid will automatically call the CellClick function with the correct parameters (gridname and cellid). Pretty much every WebGrid client-side event is fired with the first parameter being the grid's id and the second parameter will be the id of the contextual object. So in a cell event, the second parameter is the cellid. All parameters are listed in the client-side api docs.
Tony,
I have several buttons on the grid one being a delete button. How can I distinquish the correct button? Is it the same name as the key?
Thanks in advance.
{
}
</script>
You can either use the grid's BeforeDeleteRow client-side event which will only fire when a row is being deleted (through a button click or the delete key press), of you should set an explicit click handler for your button - "<button onclick='deleterow(rowid)'>Delete</button>"