SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a code (following

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 ='&');

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

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

if (i < 0) { kvp[kvp.length] = [key, value].join('='); } = 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 = '';

Doesn't redirect! So... How can I do? Any suggestion?

Thank you very much!

share|improve this question
up vote 2 down vote accepted

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

  1. Use SPRibbonPostBackCommand in conjunction with implementing IPostBackEventHandler interface for your control (server-side both)
  2. 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:

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:

share|improve this answer
Thank you! I've already deploy something working, my problem is how to pass parameters to the server side code.. Can you help me with that? Thank you! – Ziba Leah Jun 12 '12 at 6:09
Problem solved... Don't know HOW but now URL Rewriting works! – Ziba Leah Jun 12 '12 at 6:49

Your Answer


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.