In this blog I am going to tell you how you can place a custom button in Spread command bar while using Spread for MVC. If you have previously worked with Spread for ASP.net you would probably know that placing a custom button in command bar is not a difficult task. You have to override the PreRender event and put the button in command bar by finding an existing button over it. I am going to follow the same implementation here for Spread MVC which is a bit trickier. Logic behind the implementation is to place an ImageButton in command bar and handle its both the client and server side, click event. I am considering the fact that you are already aware of adding Spread MVC to your MVC project; if not, you may go through this link. Once Spread is added to the View we can access it in the controller and add handler for PreRender and ButtonCommand events:
In Spread's PreRender event I am going to attach a handler for PreRenderComplete event for the Page object. Here is the code to do that:
Now most important part of this blog comes into play. I will now add my custom image button to Spread's command bar. I will first get the parent of any existing control on command bar. For example I am going to check if Print button exists, so that I can get access to its parent which is the command bar itself. See the code below:
Next, I add an image to the image button and place it over the command bar. In code I am also adding an "OnClick" attribute which I will handle client side.
Spread's CallBack method makes an ajax call to server with a custom command name "ImageButton". This fires Spread's ButtonCommand event server side. Any command button on command bar causes triggers this event. I will check which command button is the source for this event using "e.commandName".
In button command event I set the celltype for Spread's cell to imageCellType and passed the same image which is used for ImageButton in command bar. Refer to the attached samples for complete implementation: Download C# Sample Download Vb Sample