Q:

How to insert selected items after Ribbon Click

I have a code (following http://makarandrkulkarni.blogspot.it/2010/01/new-one.html).
I have a custom WebControl which receives a postback and react with server side code. Thanks to Javascript I can read with this code the elements:
    var ctx = SP.ClientContext.get_current();
    var items = SP.ListOperation.Selection.getSelectedItems(ctx);
    var myItems = '';
    var i;
    for (i in items) {
        myItems += '|' + items[i].id;
    }
    insertParam('IDs', myItems);
    return handleCommand(commandId, properties, sequence);

I have in a variable all the selected items...
Now I need to pass this parameters to my "Server Side Script" as params... So I tried this way:
function insertParam(key, value) {
key = escape(key); value = escape(value);

var kvp = document.location.search.substr(1).split('&');

var i = kvp.length;
var x; 
while (i--) {
    x = kvp[i].split('=');

    if (x[0] == key) {
        x[1] = value;
        kvp[i] = x.join('=');
        break;
    }
}

if (i < 0) { kvp[kvp.length] = [key, value].join('='); }
document.location.search = kvp.join('&');

}
This function executed locally works but on my server doesn't work. How could I pass this simple string to my Postback method??
Even if I wrote down something like:
document.location = 'www.google.it';

Doesn't redirect! So... How can I do? Any suggestion?
Thank you very much!

A:

If you want to perform postbacks from ribbon controls, there are at least two options:

Use SPRibbonPostBackCommand in conjunction with implementing IPostBackEventHandler interface for your control (server-side both)
Use __doPostBack in JS, and then Page.Request["__EVENTTARGET"] server-side

Let me explain both approaches in detail.
1. SPRibbonPostBackCommand approach
The post you presented above hints the first approach, however it doesn't provide clear example of how to implement it.
I'd recommend another post on the same topic, which is a bit more apprehensible:

http://sharepointsolutions.com/sharepoint-help/blog/2009/10/creating-a-custom-ribbon-tab-in-sharepoint-2010/ (see section "Additional Ribbon Commands")

In brief, first you should add SPRibbonPostBackCommand object to commands collection which is passed to SPRibbonScriptManager.Register* functions. Then, you should implement IPostBackEventHandler and SPRibbonPostbackCommand.DeserializePostBackEvent function to get id and arguments of the command.
2. __doPostBack approach
The other approach could be a bit more easier to understand, but a bit more hardcore at the same time. Use __doPostBack JS function, and then add basic code on server, which analyses Page.Request["__EVENTTARGET"]. Parameters for the postback could be passed by serializing/deserializing data through Page.Request["__EVENTARGUMENT"].
I've already posted links and examples for this approach under one of your previous questions:

How to invoke server side code from Ribbon

