Pregunta

I want to add a button to the sitecore page editor ribbon and I want it to work as a link. For example, when I click this button, the page should be redirected to HOMEURL/sample.aspx.

I have written a class, that inherits from Command.

public class addlink : Command
{
    public override void Execute(CommandContext context)
    {
        Sitecore.Web.WebUtil.Redirect("/sample.aspx");
    }
}

Then, for this webedit ribbon element in core db, I gave as the click event webedit:addlink. The onclick event of this link on the browser is javascript:return scForm.invoke('webedit:addlink', event).

So, the redirect does not happen. How can I add a link to the page editor ribbon? I would appreciate any suggestions to improve my class or other approaches are also welcome.

Thanx

¿Fue útil?

Solución

You need to register your command in Sitecore configuration. Either create your own MyCommands.config file in App_Config/Include with content:

<configuration>
  <command name="webedit:addlink" type="My.Assembly.Namespace,My.Assembly"/>
</configuration>

or update one of the existing files with the command definition.

EDIT IN ANSWER TO YOUR COMMENT:

The reason why your code doesn't work is that you're trying to redirect the response of the POST call which is requested while button is clicked. What you need to do is to register a javascript that will redirect the parent window after the response from Sitecore comes back, like TwentyGotoTen wrote in his post below.

public override void Execute(CommandContext context)
{
    Sitecore.Web.UI.Sheer.SheerResponse
        .Eval("window.top.location.href='http://google.com';");
}

Otros consejos

I think the redirect needs to be done client side, which can be achieved by adding something like this to your command:

SheerResponse.Eval("window.parent.location.href='/sample.aspx';");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top