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

Show a popup on cancel event of radgrid edit and insert mode

7 Answers 246 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dorababu
Top achievements
Rank 1
Dorababu asked on 16 Oct 2012, 07:32 AM
Hi all I would like to show a pop up on cancel event of both insert and edit of radgrid. Means when ever user clicks on cancel I would like to show a popup saying are you sure you want to cancel if yes means I would like to cancel the update or insert. If no I would like to make insert and edit as it is can some one help me

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Oct 2012, 07:44 AM
Hi,

Try the following code to show a popup on clicking cancel button.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)
 {
    GridEditableItem item = (GridEditableItem)e.Item;
    LinkButton link = (LinkButton)item.FindControl("CancelButton");
    link.Attributes.Add("onclick", "popup();return false;");
 }
}
JS:
<script type="text/javascript">
function popup()
{
 window.confirm("Do  you sure you want to cancel?");
}
</script>

Thanks,
Shinu.
0
Dorababu
Top achievements
Rank 1
answered on 16 Oct 2012, 07:56 AM
Thanks shinu how can I set edit mode to false when I click on Ok and to true when clicking on false in javascript
0
Dorababu
Top achievements
Rank 1
answered on 16 Oct 2012, 08:14 AM
Also is it possible to show Radwindowmanager instead of normal confirm
0
Shinu
Top achievements
Rank 2
answered on 17 Oct 2012, 04:14 AM
Hi,

In order to show radconfirm, try the following javascript. Make sure that you have RadWindowManager on the page. You can pass the response from the RadConfirm using AjaxRequest.
JS:
<script type="text/javascript">
function popup()
{
 window.radconfirm("Do  you sure you want to cancel?");//for showing radconfirm
}
function confirmCallBackFn(arg) {
  var ajaxManager = $find("<%=RadAjaxManager1.ClientID%>");
  if (arg)
  {
      ajaxManager.ajaxRequest('true');
  }
  else
  {
     ajaxManager.ajaxRequest('false');
  }
}
</script>
aspx:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
  <AjaxSettings>
       <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
            <UpdatedControls>
                  <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>
C#:
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
    if (e.Argument.ToString() == "true")
    {
        //your code
    }
    else
    {
       //your code
    }
}

Thanks,
Shinu.
0
Dorababu
Top achievements
Rank 1
answered on 17 Oct 2012, 01:08 PM
Didn't worked can you attach a sample code if you have done this kind of requirement
0
NETSI
Top achievements
Rank 1
answered on 18 Dec 2019, 08:38 PM
This does not work as intended. The window will show on pressing Insert or Edit as well, not just on Cancel. Isn't there a way to differentiate the three from each other inside the ItemCreated event?
0
Eyup
Telerik team
answered on 23 Dec 2019, 06:42 AM

Hello,

 

You can achieve this requirement using the following approach:

            function pageLoad(app, args) {
                $telerik.$("div.RadGrid .rgEditForm .rgCancel").on("mousedown", function (e) {
                    if (confirm("Continue?")) {
                        this.click();
                    }
                });
            }
I hope this will prove helpful.

 

Regards,
Eyup
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Dorababu
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Dorababu
Top achievements
Rank 1
NETSI
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or