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

We've created a custom New Item page for our list on our site in Sharepoint 2010 with this code:

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <table id="tblForm" cellpadding="0" cellspacing="0" >
        <SharePoint:ListFieldIterator ID="lfiARPieces" runat="server" ControlMode="New" />
        <tr>
            <td align="right">
                <SharePoint:SaveButton ID="btnSave" runat="server" />
            </td>
        </tr>
    </table>
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
New ARPiece
</asp:Content>

We want to show a ribbon that is normally displayed on New Item page and access buttons, for example a Save button to bind some action to it (we actually want the default action to fire - just to save the item, but without the context the Save button will probably not know what to save). We managed to show the ribbon:

protected override void OnPreRender(EventArgs e)
        {
            SPRibbon current = SPRibbon.GetCurrent(this);
            if (current != null)
            {
                //
                current.Enabled = true;
                current.Minimized = false;
                current.CommandUIVisible = true;
                current.MakeTabAvailable("Ribbon.ListForm.Edit");
                current.InitialTabId = "Ribbon.ListForm.Edit";
                current.MakeContextualGroupInitiallyVisible("Ribbon.ListForm.Edit.Commit", string.Empty);      
}
}

What should we do to bind the actions?

share|improve this question
add comment

3 Answers 3

To do this your custom page needs to be application (layout) page and it needs to be attach to content type of target list as new form. By doing this your page 'runs under new item context'. Best way to do this is by code in feature activation event.

After that you need to build and deploy custom ribbon definition. You can use original Ribbon.ListForm.Edit definition from 14\TEMPLATE\GLOBAL\XML\CMDUI.xml as starting point but you need to change original IDs and Commands.

Next step is to attach your new ribbon to application page and to attach some custom action to your ribbon button(s). This is not so simple and I found only one blog with decent explanation how to do this: http://sharepointuidesign.wordpress.com/2011/03/13/creating-a-custom-ribbon-tab-in-sharepoint-2010/

Final step is to save new item.
I am using Microsoft.Sharepoint.WebControls.FormField for list field input and for saving I am simply using SPContext.Current.ListItem.Update() in SPRibbonPostBackCommand (explained in link I provided). Since my page runs as new form of my custom content type I am in right context to do this. Not sure for ListFieldIterator but my guess is it will also work. Different approach is to use standard ASP.NET controls for input and then create new SPListItem fully in code.

I never found a way to use original Ribbon.ListForm.Edit nor original scripts but I am still looking.

All of this is too complex to explain in few sentences but it can be done. I will try to provide more info if needed.

share|improve this answer
add comment

If you want to perform an action on save, there is a standard Sharepoint way to achieve this - you should simply use ItemUpdating event receiver, because actually the item can be updated from many different places, omitting your custom form, just for example this can be the list datasheet view or whatever...

MSDN article: How to create an Event receiver

If you want to perform some client-side operations, most likely you will need to create your own ListEdit tab (the original xml definition code can be copy-pasted from 14\TEMPLATE\GLOBAL\XML\CMDUI.xml), and don't forget about the form save button, it should be redefined too. I think it is not a simple task and I don't recommend you to go this way.

Sharepoint has many extension points, so depending on actions which you want to bind to the Save button, I think there is another way to achieve your goal, not touching the ribbon...

share|improve this answer
    
please read carefully! you're not answering my question. i do not want to override default save button functionality. i have a custom page that does not have ribbon attahced, because it's custom, and i want to show that ribbon. if the save button works on it - it's fine with me and i don't need to ovchange anything. –  agnieszka Jun 8 '11 at 9:54
    
That is how I understand your question. It's great that you corrected it, because it was really unclear. –  Andrey Markeev Jun 8 '11 at 11:34
add comment

I think you need to customize the ribbon behavior for the page... You can add new Tabs and Buttons to the Ribbon as per your needs...

Have a look at Chris'O Brien's article series to customize the Ribbon

Also you can create Custom Actions that execute your custom code, have a look at this article

share|improve this answer
add comment

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.