Developer forum

Forum » Development » Ribbonbar Extensibility

Ribbonbar Extensibility


Reply
It might just be because it's still early, but I can't seem to get the serverside event working on a RibbonbarButton.

I'm trying the following:

public override void Load()
{
   ...
   RibbonBarButton btn = new RibbonBarButton();
   btn.ID = "btnMyID";
   btn.Text = "MyBtn";
   btn.Size = Dynamicweb.Controls.Icons.Icon.Size.Large;
   btn.Image = Dynamicweb.Controls.Icons.Icon.Type.Key;
   btn.EnableServerClick = true;
   btn.Click += new EventHandler<EventArgs>(btn_Click);
   ...
}

void btn_Click(object sender, EventArgs e)
{
   // do stuff
}

But the btn_Click EventHandler never catches the event.

What am i doing wrong?

Replies

 
Reply
Hello,

Could you elaborate your problem ?

1. On what page you're trying to execute your add-in (is this a standard Dynamicweb page or is this the page that you created by yourself) ?

2. Do you place an add-in onto the "Add-ins" tab or do you use an existing tab ?

- Pavel
 
Reply

i'm trying to add a buttom to the edit page ribbonbar, in the administration.


the button is added nicely, but the onClick event never fires.


Here's my complete test code:
 

//-----------------------------------------------------------------------
// <copyright file="addinTest.cs" company="Corbiz">
//     All rights reserved ® Corbiz
// </copyright>
//-----------------------------------------------------------------------
 

namespace addinTest
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using Dynamicweb;
    using Dynamicweb.Controls;
    using Dynamicweb.Controls.Extensibility;
    using Dynamicweb.Extensibility;


    /// <summary>
    /// For testing purposes
    /// </summary>
    [AddInName("addinTest")]
    [AddInAuthor("Corbiz")]
    [AddInDescription("For testing purposes ")]
    [AddInTarget(RibbonBarAddInTarget.General.PageEdit)]
    public class addinTest : RibbonBarAddIn
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="addinTest"/> class.
        /// </summary>
        /// <param name="ribbon">An instance of <see cref="T:Dynamicweb.Controls.RibbonBar">RibbonBar</see> object that contains an add-in.</param>
        /// <remarks></remarks>
        public addinTest(RibbonBar ribbon)
            : base(ribbon)
        {
           
        }
 

        /// <summary>
        /// Performs "Load" stage.
        /// </summary>
        /// <remarks></remarks>
        public override void Load()
        {
            RibbonBarGroup group = new RibbonBarGroup();
            group.Name = "TestGroup";

            RibbonBarButton btn = new RibbonBarButton();
            btn.ID = "btnMyID";
            btn.Text = "MyBtn";
            btn.Size = Dynamicweb.Controls.Icons.Icon.Size.Large;
            btn.Image = Dynamicweb.Controls.Icons.Icon.Type.Key;
            btn.EnableServerClick = true;
           
            btn.Click += new EventHandler<EventArgs>(btn_Click);
            btn.OnClientClick = "Ribbon.toggleActive('" + btn.ClientID + "')";

            group.AddItem(btn);
            this.Ribbon.InsertGroup("Menupunkt", group, 6);
        }
       
        void btn_Click(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
    }
}
 

 
Reply
Hello,
 
This particular page doesn't contain a form with "runat=server" attribute so ASP.NET has no way to determine (by examining the value of the "__EVENTTARGET" field)  which control has caused a postback.
 
I would suggest not to use the server-side events in your add-ins at all (since some of the standard Dynamicweb pages designed in such a way so they don't support this kind of events). If the data needs to be persisted when the page is submitted then please subscribe to "Save" event which is the member of the Ribbon data context object (section 4.3, Dynamicweb Ribbon Extensibility). Otherwise please use AJAX (either by using a hidden iframe or by using a Prototype JS library's capabilities. The library is the part of the Dynamicweb distribution) to store your data.
 
- Pavel
 
Reply
Same problem here.
 
Reply
As Pavel wrote above, you have to use Ajax or subscribe to "Save" event, to save you data.

I fixed my issue with Ajax.

 

You must be logged in to post in the forum