Question

SB Ali on Wed, 13 Sep 2017 09:46:22


hi,

I have 2 List which are related

List 1 and List 2

I have added the related Listview Webpart which is List 2  in DispForm.aspx page of List 1

so from here I want to delete the items of List 2 and after deleting it should be redirected to the same DispForm.aspx below is the screenshot of the page.

I can delete it from the List Item Menu but it is redirecting to Allitem.aspx page of List 2.

below is the screenshot for reference.


sal



Replies

SClark_EasyBins on Thu, 14 Sep 2017 14:14:22


The ?Source= parameter in the URL specifies the "redirect".

So, perhaps you'd have to manipulate your own URL to handle the deletions, and include the ?Source= in it. 

Fwiw, it redirects to AllItems.aspx, because that is your default view.  If you just supply the list name, and not the view name, it will automatically reset to include the default view name.

Lee Liu on Fri, 15 Sep 2017 10:21:22


Hi,

According to your problem, I made an simple example and test successfully for you. It’s divided two steps:

First, you need to hide the default option “Delete Item”. You can add a web part of “Script Editor” and write some code to do it, here is my code may help you.

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
<style type="text/css">
#ID_DeleteItem
{
    display:none
}
</style>

After you add this code to “Script Editor” web part, you can see the default “Delete Item” option is hidden.

Second, you should extend your ECB UI with adding a new “Delete Item” option to replace the hidden one. You can create an farm solution with Visual Studio and add an “Empty Element” item to your solution(Don’t forget to add this element to your feature). Then you can write some code in your element file, here is my code here is my code may help you.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction   
    Location="EditControlBlock"   
    RegistrationType="List"   
    RegistrationId="100"   
    Id="DevLeap.CustomActions.DemoECB.SampleAction"   
    Title="Delete Item"   
    Description="Sample custom action."
     >
     <UrlAction Url="javascript:
                                function onQuerySucceeded() {
                                    alert('Item deleted success');
                                    window.location.reload();
                                 }

                                function onQueryFailed() {
                                    alert('Item deleted failed');
                                     window.location.reload();
                                }
                               
                                var ctx = SP.ClientContext.get_current();
                                
                                var itemID = $('.s4-itm-selected').attr('id').split(',')[1];                                                                                                    
                                
                                var oList = ctx.get_web().get_lists().getByTitle('Your List Title');
                                
                                var oListItem = oList.getItemById(itemID);
                                
                                if(confirm('are you sure delete it into recycle bin?'))
                                 {
                                   oListItem.recycle();
                                
                                  ctx.executeQueryAsync(onQuerySucceeded,onQueryFailed);
                                 }
                                
                                "/>
  </CustomAction>

</Elements>

Finally, deploy your solution and you will see your desired result appearing.

Best regards

Lee Liu

Please remember to mark the replies as answers if they help.

If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.



SB Ali on Mon, 06 Nov 2017 07:18:04


HI Lee,

Thanks , it is working.

SB Ali on Sun, 26 Nov 2017 07:18:12


hi,

for Task list it is not working , below is the code of element.xml file.

I changed the RegistrationId from 100 to 107, but still it is not working.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction   
    Location="EditControlBlock"   
    RegistrationType="List"   
    RegistrationId="107"   
    Id="DevLeap.CustomActions.DemoECB.SampleAction"   
    Title="Delete Item"   
    Description="Sample custom action."
     >
     <UrlAction Url="javascript:
                                function onQuerySucceeded() {
                                    alert('Item deleted success');
                                    window.location.reload();
                                 }

                                function onQueryFailed() {
                                    alert('Item deleted failed');
                                     window.location.reload();
                                }
                               
                                var ctx = SP.ClientContext.get_current();
                                
                                var itemID = $('.s4-itm-selected').attr('id').split(',')[1];                                                                                                    
                                
                                var oList = ctx.get_web().get_lists().getByTitle('Your List Title');
                                
                                var oListItem = oList.getItemById(itemID);
                                
                                if(confirm('are you sure delete it into recycle bin?'))
                                 {
                                   oListItem.recycle();
                                
                                  ctx.executeQueryAsync(onQuerySucceeded,onQueryFailed);
                                 }
                                
                                "/>
  </CustomAction>

</Elements>