Developer forum

Forum » Development » Addins and CustomModule Questions

Addins and CustomModule Questions

Jan Sangill
Reply

Hi,

Question1:

Is there any place I can find an example of how an addin and RIbbonBar works, when wanting to use a modal window. Only examples I can find, uses PopupWIndow, but I read I am supposed to use dialog now. I cant seem to find any examples on how to implement though.

Question 2:

If you want to add a CustomModule, and make use of Dw's GUI - and DW9 - is this the guide to still follow?
http://developer.dynamicweb-cms.com/documentation/for-developers/dynamicweb-custom-modules/building-modules-series/7-steps-to-building-a-custom-module-hands-on.aspx
Or is there an updated better approach for DW9?

Any advice appreciated!
 


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

1) RibbonBar with dialog window

Here is a very basic example of how to implement a ribbon bar add-in with a button that opens a dialog...

using Dynamicweb.Controls;
using Dynamicweb.Controls.Extensibility;
using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Security.UserManagement;
 
namespace MyRibbonBars
{
    [AddInTarget(RibbonBarAddInTarget.UserManagement.UserEdit)]
    public class UserEditRibbonBar : RibbonBarAddIn
    {
        public UserEditRibbonBar(RibbonBar ribbon) : base(ribbon)
        {
        }
 
        public override void Load()
        {
            // Get the data from current context
            var user = Ribbon.DataContext.DataSource as User;
            if (user == null)
            {
                return;
            }
 
            // Add the dialog
            var dialog = new Dialog()
            {
                ID = "MyCustomDialog",
                Title = "Test Dialog"
            };
            
            AddWindow(dialog);
 
            // Add some content to the dialog
            var dialogContent = new System.Web.UI.HtmlControls.HtmlGenericControl("div")
            {
                InnerText = $"Hello! The username is: {user.UserName}"
            };
 
            dialog.Controls.Add(dialogContent);
            
            // Add a ribbon bar button for opening the dialog
            var group = Ribbon.CreateGroup("MyCustomTab""MyCustomGroup");
 
            var button = new RibbonBarButton()
            {
                Text = "Test Button",
                OnClientClick = $"dialog.show('{dialog.ID}');"
            };
 
            group.AddItem(button);
        }
    }
}

2) Module implementation hasn't really changed.

In DW9 you can use module annotations, but it's just an alternative way of registering a module. You can find an example of that in the API documentation for ContentModule class.
 

Votes for this answer: 1
 
Jan Sangill
Reply

TY Morten,

Regards to the dialog, that did the trick.

I got my code working, by adding my html directly via the addin. However, if I wanted to do like before, with ContentUrl -
so it renders from one of my custom modules. Which dialog options should be used then?

In regards to custom modules. When following the step by step guide, I end up with an error:

Filen eller assemblyen 'HttpCompression'
Most likely because the web.config created by the dw8 template installer is out of date OR?
 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

You can add any content to the dialog by using controls. If you want do display content from a specific URL then you could either add an iframe control or include a script that loads content using ajax.

var dialogContent = new System.Web.UI.HtmlControls.HtmlIframe
{
    Src = "/custommodules/mymodule/somepage.aspx"
};
 
dialog.Controls.Add(dialogContent);

The HttpCompression module is not used in DW9. Looks like you are using an old web.config file. Always ensure that web.config is updated when you upgrade a solution.
Take a look at Installing DynamicwebUpgrading a custom solution and Extending - an introduction. You can also download the DW9 templates for Visual Studio and give them a try.

Best regards,
Morten

Votes for this answer: 1

 

You must be logged in to post in the forum