Most of the examples related to ribbon button actions involve opening dialog. However, if you need to send post back request to the same page/dialog where the ribbon exists, you need to trick a bit. Let’s explain how you can do so.
Define Ribbon XML
You can define the postback action in the command action in Ribbon xml file. To do so, you can use javascript function _doPostBack(‘token’,’’). This will send a postback request to the same page.
<CommandUIHandlerFigure 1: PostBack action defined in Ribbon xml
Command="MyButton.Command"
CommandAction="javascript:__doPostBack('MyButtonPostback','');"
EnabledScript="true" />
Identify the PostBack request in the page
The second step is to identity from code behind file, if the postback occurred from ribbon button’s action. From the page load, you can check if the postback occurred due to the command “MyButton.Command”. To do so we can have a check shown below in the page load method.
if (Page.Request["__EVENTTARGET"] == "MyButtonPostback")
{
//The ribbon button initiated the postback
}
Though this is very simple trick but might be helpful for someone.
nice post
ReplyDelete