Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to display a warning message whenever user clicks the Cancel button on the ribbon of EditForm.aspx OR Hide/Remove the Cancel button from the Ribbon.

Both solutions are most welcome.

enter image description here

share|improve this question

1 Answer 1

up vote 2 down vote accepted

If you want to hide look at this article. In your situation definition should looks like this one:

 <CustomAction
     Id="RemoveRibbonButton"
     Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.DocLibListForm.Edit.Commit.Cancel"/>
      </CommandUIDefinitions>
    </CommandUIExtension>
  </CustomAction>

Small tip: to quickly find button's id you can use inspect html tool in your favorite browser, inspect whole button (it will be html a element with id Ribbon.DocLibListForm.Edit.Commit.Cancel-Large), remove -Large postfix and this is your id in most situations. If button is more complicated, you can find it by this html id in cmdui.xml file, which contains definitions for all ribbon elements.

edit:
If you want display warning, you need replace default button with your own and with your own javascript handler:

 <CustomAction
     Id="RemoveRibbonButton"
     Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.DocLibListForm.Edit.Commit.Cancel"/>
      </CommandUIDefinitions>
    </CommandUIExtension>
  </CustomAction>
  <CustomAction Id="2C9619A8-CCD8-4984-909C-2C1B7FE794E4"
                Location="CommandUI.Ribbon" >

    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.DocLibListForm.Edit.Commit.Controls._children">
          <Button
                Id="E6DF7DBA-AC35-4ABA-9A12-4C87DAECA8BE"
                Sequence="20"
                Command="ConfirmClose"
                Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png" Image16by16Top="0" Image16by16Left="-248"
                Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png" Image32by32Top="-448" Image32by32Left="-288"
                LabelText="$Resources:core,cui_ButListFormCancel;"
                ToolTipTitle="$Resources:core,cui_ButListFormCancel;"
                ToolTipDescription="$Resources:core,cui_STT_ButListFormCancel;"
                TemplateAlias="o1"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="ConfirmClose"
                          CommandAction="javascript:if(confirm('Are you sure?')){SP.UI.ModalDialog.get_childDialog().close();}"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

Button definition I copy from cmdui.xml, but replace with custom close command.
note: this code replaces all close buttons on all document libraries, if you want limit it only to specific list type or content type, use RegistrationId and RegistrationType attributes on CustomAction.
note2: if you have more complicated confirmation logic, place it in separate javascript file and refer from handler something like this:

CommandAction="javascript:myConfirmationFunction();"
share|improve this answer
    
Thanks Kai for your help –  Zakir HC May 15 '12 at 11:49
    
@ZakirHC if the answer was the solution, please mark as answer –  Anders Rask May 15 '12 at 12:14
    
To display warning message box is a priority, kindly reply if any one has a solution, thanks. –  Zakir HC May 16 '12 at 4:55
    
@ZakirHC, please refer to my update –  Kai May 16 '12 at 8:32
    
Thanks Kai for your kind help !!! Your efforts are appreciated –  Zakir HC May 16 '12 at 11:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.