Answered by:
Custom Ribbon Button server side click handling

Question
-
Hi,
I am working on SharePoint 2010. In my application we need to perform some server side logic on click of custom ribbon button, I have added a custom button to sharepoint ribbon but not sure how to execute server side logic on ribbon button click.
How to Specify the Assembly/Class/Method name for button click handler? Can some one post a sample on this?
My CustomAction definition is below:
<CustomAction
Id="MyTaskList.Complete"
Title="Complete"
Description="Completes tasks"
RegistrationId="10006"
RegistrationType="List"
Location="CommandUI.Ribbon"
Sequence="1">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">
<Button
Id="CompleteButton"
LabelText="Complete"
Sequence="1"
Command="CompleteButton"
Image32by32="/_layouts/complete.PNG"
TemplateAlias="o1"/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="CompleteButton"
EnabledScript="javascript:EnableCompleteButton();"
CommandAction="" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>Thanks,
SujanakarTuesday, October 19, 2010 10:05 AM
Answers
-
Hi,
You can't invoke server side code directly from this kind of CustomAction. Instead you must use a JavaScript function to invoke something to run the code. I usually use a confirmation form.
See this post on my blog for the basic technique. Passing Values from a List Custom Action to Server Code
Hope this helps,
--Doug
- Marked as answer by Aaron Han - MSFT Thursday, October 28, 2010 9:41 AM
Tuesday, October 19, 2010 12:07 PM
All replies
-
Hi,
You can't invoke server side code directly from this kind of CustomAction. Instead you must use a JavaScript function to invoke something to run the code. I usually use a confirmation form.
See this post on my blog for the basic technique. Passing Values from a List Custom Action to Server Code
Hope this helps,
--Doug
- Marked as answer by Aaron Han - MSFT Thursday, October 28, 2010 9:41 AM
Tuesday, October 19, 2010 12:07 PM -
You could also use the:
CommandAction="javascript:__doPostBack('SomeAction', 'SomeParameter')"
And then register a custom pageheader using something like:
<Control Id="AdditionalPageHead" Sequence="150"
ControlClass="class"
ControlAssembly="assembly" />after your custom action, and in your class you could use
if (this.Page.Request["__EVENTTARGET"] == "SomeAction")
{
SPListItem currentItem = SPContext.Current.ListItem;
}Tuesday, October 19, 2010 12:20 PM -
create a dialog page and pass the desired paramets to the page which will execute your custom code. see the related post below.
How do I add a Button in the ribbon which executes server side code
Isha kapoor My SharePoint Blog Follow meTuesday, October 19, 2010 3:52 PM -
I have blogged on this:
http://jasear.wordpress.com/2010/11/21/sharepoint-2010-custom-action-that-executes-custom-code/
Basically, you create a custom action which is just a link to an apx page with code behind. In the page load you can run your custom code.
Visit my blog http://jasear.wordpress.comMonday, November 29, 2010 5:31 PM -
Server side code can be executed on ribbon button click in several ways.
- Using JavaScript form Submit.
- Using JavaScript _dopostback
- Using SharePoint Page Dialog framework
See this for more information: http://www.sharepointnadeem.com/2012/07/invoke-server-side-code-on-sharepoint.html
- Proposed as answer by NadeemYousuf Sunday, July 29, 2012 9:26 AM
- Edited by NadeemYousuf Saturday, February 7, 2015 9:07 AM
Sunday, July 15, 2012 6:18 AM