This is a migrated thread and some comments may be shown as answers.

Cancel out of transaction in OnItemCommand

2 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mikhail
Top achievements
Rank 1
Mikhail asked on 14 May 2008, 03:43 PM
Hello everyone,
Is there a snippet of code that allows you to cancel out of the update (or delete, add, etc) transaction inside the OnItemCommand? I would first like to show an alert box, focus on a textbox, and leave the page as it is without updating it.

I am doing this using a grid with inline editing, ajax enabled.

Here is my code behind:

    Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As GridCommandEventArgs)  
        If ((e.CommandName = "Update"AndAlso (TypeOf e.Item Is GridEditableItem)) Then 
            Dim editeditem As GridEditableItem = CType(e.Item, GridEditableItem)  
            Dim txtName As TextBox = CType(editeditem("NameColumn").Controls(0), TextBox)  
            If txtName.Text = "" Then 
                Utils.ShowMessage("Please enter a value for the name.", Page)  
                txtName.Focus()  
                ' Cancel out of update transaction  
            End If 
        End If 

Is there a better way of doing the exact same logic as above? If there is, please let me know too!

Thanks!

2 Answers, 1 is accepted

Sort by
0
Mikhail
Top achievements
Rank 1
answered on 14 May 2008, 06:00 PM
Well I was able to solve the cancelling out of the transaction. I just used e.Canceled = true.

now i am having troubles in displaying the alert box inside the ItemCommand function

    Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As GridCommandEventArgs)  
        If ((e.CommandName = "Update"AndAlso (TypeOf e.Item Is GridEditableItem)) Then 
            Dim editeditem As GridEditableItem = CType(e.Item, GridEditableItem)  
            Dim txtName As TextBox = CType(editeditem("NameColumn").Controls(0), TextBox)  
            If txtName.Text = "" Then 
                ' Cancel out of update transaction  
                e.Canceled = True 
                Utils.ShowMessage("Please enter a value for the name.", Page)  
                txtName.Focus()  
            End If 
        End If 
    End Sub 

My Utils.ShowMessage is:

    Public Shared Sub ShowMessage(ByVal sMessage As StringByVal page As Page)  
 
        sMessage = sMessage.Replace(ControlChars.CrLf, "<BR>")  
        page.ClientScript.RegisterStartupScript(page.GetType"""<script language=""javascript"">" & _  
                               "alert('" & sMessage & "');" & _  
                             "</script>")  
    End Sub 

Is it a problem to pop up an alert box inside ItemCommand?
0
Sebastian
Telerik team
answered on 17 May 2008, 08:35 AM
Hello Mikhail,

If you ajaxified the grid via RadAjaxManager, consider utilizing its ResponseScripts collection to show the alert dialog. Alternatively, show RadWindow in alert mode.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Mikhail
Top achievements
Rank 1
Answers by
Mikhail
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or