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

Prompt to save change in edit mode

5 Answers 323 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 04 Sep 2008, 04:26 PM
I have a RadGrid that uses Inline edit mode.  My grid only supports editing one row at a time and all works fine so long as the user clickes the update button after editing the row to commit the changes to the database.

If the users has row 1 in edit mode and does not click update, but selects a different row to place into edit mode, I would like to pop up a message box asking the user if they want to save their changes before moving to edit the new row.

How can I accomplish this?  When a new row is placed into edit mode the previous row does not get a cancel event for me to trap.

Tim

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 04 Sep 2008, 06:20 PM
Hello Tim,

This is one possible approach:
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    if (e.CommandName == RadGrid.CancelCommandName && e.Item.IsInEditMode) 
        Session["editMode"] = null
    if (e.CommandName == RadGrid.UpdateCommandName) Session["editmode"] = null
    if (e.CommandName == RadGrid.EditCommandName)        { 
        if (Session["editMode"] != null
            e.Canceled = true
        else 
            Session["editMode"] = "edit"
    } 

Greetings,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shinu
Top achievements
Rank 2
answered on 05 Sep 2008, 04:50 AM
Hi Tim,

You can also have a look at the following demo which sets the Grid in edit mode on double clicking a row and displays  a user-friendly confirm dialog to prompt whether the operation should be propagated or not.
Edit on double-click

Thanks
Shinu.
0
Giovanni
Top achievements
Rank 1
answered on 11 Apr 2011, 10:04 AM
I know this post is very outdated, but I have one question : How can I achieve the same result (Prompt the user to choose if save or not to save) in client-side ?

Let me explain :
The user choose to insert a new row (in editform), then I have to validate a value.
If this value is <= X, then I have to prompt, otherwise it should insert the element without prompt the user.
I guess I have to do this client side, but I cannot find where to catch the 'onclick' event for the Insert button.

Thanks

Giovanni
0
Shinu
Top achievements
Rank 2
answered on 11 Apr 2011, 10:31 AM
Hello,

You can attach the onClick event to the insert button in the ItemCreated like below.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
  {
      if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
      {
          GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
          LinkButton insert = (LinkButton)insertItem.FindControl("PerformInsertButton");//accessing the insert button
          insert.Attributes.Add("onclick", "insert();");
      }
  }

javascript:
<script type="text/javascript">
    function insert()
    {
     //your code here
    }
</script>

Thanks,
Shinu.
0
Giovanni
Top achievements
Rank 1
answered on 11 Apr 2011, 10:42 AM
thank you very much, that's a smart way to attach a client function indeed :-)
I'll try ASAP and let you know. Your help is appreciated

Thanx,
Giovanni
Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Shinu
Top achievements
Rank 2
Giovanni
Top achievements
Rank 1
Share this question
or