Sunday, February 13, 2011

Popping up Fancybox from SSRS Report

When do I really need it? You might want user to take some action depending on the report you are showing up. Ex. You are generating a report for 3 products and its performance over a period, now you may want to put the product on the showcase.

What you really do is, call a page and pass the product id to it and user might want to add some comments and take some action.

How do I do it? Using Javascript. You create a text field and set the action on the text field as Go to URL. In the URL field add the expression as

="javascript:void(MyScriptMethod('"+First(Fields! ProdId.Value, "DataSet1")+"'))"


Now the method should be residing on the page which is hosting the report viewer control.



function MyScriptMethod(prodId) {

// fancy box enabled link
var link = $("#lnkProdEval").attr("href");

//remove the old query string parameter
link = link.split('?')[0];

//add a new parameter - product Id
link = link + '?Id=' + prodId ;
$("#lnkProdEva").attr('href', link);

//now click the link through the code.
// Make sure you put this link in a invisible div, so user cannot
// click it directly
$("#lnkProdEval").click();
}


lnkProdEval is the ID of the Anchor, on which fancy box is enabled. You can get more detail about hooking a fancy box @ http://fancybox.net/howto