Invoke server side code on SharePoint custom ribbon button in background

It is happen to be SP2010 and above not allowing Custom Ribbon Actions not allowed to have ControlAssembly and ControlClass to execute server side code (which happen to be in SP2007).  By the way this is possible with some other locations like context menu even with SP2010.

But there are few workarounds that can make up to this. Three of such workarounds have being clearly showcased by Naddem Yousuf on his blog. However I wanted to have a button which will trigger a update in background while the user remains on the List Form. So I used Nadeem’s 1st option with slight modification to JS event handler. Here is my modification.

    var iframe = document.createElement(“iframe”);
    iframe.setAttribute(“style”, “display:none”);
    iframe.setAttribute(“name”, “hiddeniFrame”);
    document.body.appendChild(iframe);

    var form = document.createElement(“form”);
    form.setAttribute(“method”, “post”);
    form.setAttribute(“action”, pageUrl);
    form.setAttribute(“target”, “hiddeniFrame”);
    document.body.appendChild(form);
    form.submit();

Here I am creating a hidden iframe and using it as the target of the form so that everything from the control response will be hidden from the form.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s