Developer forum

Forum » Development » AddIn Dialog
Daniel Hollmann
Reply

Hi Community

I have a working AddIn Button, that needs an extension.
Currently it’s a button of the class RibbonBarButton that works with the “Click” event, that triggers a serverside function

Code looks something like this:
 



                RibbonBarGroup group = base.CreateDefaultContainer();

                RibbonBarButton button = new RibbonBarButton();


                button.Text = "Shipping Label";

                button.Icon = Dynamicweb.Core.UI.Icons.KnownIcon.Label;


                button.Size = Icon.Size.Large;

                button.EnableServerClick = true;

                button.Click += button_Click;

                group.AddItem(button);

….

And button_click is a method that has this form:

void button_Click(object sender, EventArgs e)

….


The extension is to have a Frontend Dialog to pop up, to take some user inputs before running the button_Clicked method, but I can’t seem to find a good way to do that.

The RibbonBarButton comes with a OnClientClick method, and by using the info from this post ( https://doc.dynamicweb.com/forum/development/development/addins-and-custommodule-questions ) I was able to create a Dialog for the frontend, but my problem is now getting that data to the button_Click method. I can’t use the serverside Click method, that would run simultaneously with the OnClientClick method. 

Is there any good way to get the data from the dialog, back to my serverside function? I can’t seem to find good examples on how to implement AddIns.


Replies

 
Daniel Hollmann
Reply

 

Here is my code for the Load Method

public override void Load()
        {
            try
            {

                RibbonBarGroup group = base.CreateDefaultContainer();
                RibbonBarButton button = new RibbonBarButton();

                var dialog = new Dialog()
                {
                    ID = "CustomDialog",
                    Title = "Shipment Labels",
                    ShowClose = true
                };

                AddWindow(dialog);

                var dialogContent = new System.Web.UI.HtmlControls.HtmlGenericControl("form")
                {
                    InnerHtml = $"<div style=\"padding:15px\"" +
                    $"<label for=\"shipmentLables\">Shipment Labels (Sended from Unilabs)</label><br>" +
                    $"<input type=\"number\" min=\"0\" max=\"10\" id=\"shipmentLables\" name=\"shipmentLables\" value=\"1\"><br>" +
                    $"<label for=\"returnLables\">Return Labels (Sended from Customer)</label><br>" +
                    $"<input type=\"number\" min=\"0\" max=\"10\" id=\"returnLables\" name=\"returnLables\" value=\"1\"><br>" +
                    $"<input type=\"submit\" value=\"Submit\">" +
                    $"</div>"
                };

                dialog.Controls.Add(dialogContent);

                button.Text = "Shipping Label";
                button.Icon = Dynamicweb.Core.UI.Icons.KnownIcon.Label;
                button.OnClientClick = $"dialog.show('{dialog.ID}')";

                button.Size = Icon.Size.Large;
                group.AddItem(button);
            }
            catch (Exception ex)
            {
                LogManager.System.GetLogger(LogCategory.Health, "AddInShipmentLabel").Error($"Could not load OrderList Add In {ex.Message}", ex);
            }
        }

 

 

And this is the code for the button_Click method:

void button_Click(object sender, EventArgs e)
        {
            ILogger Logger = LogManager.System.GetLogger(LogCategory.Health, "AddInShipmentLabel");
            Dynamicweb.Environment.IResponse response = Context.Current.Response;
            try
            {
                List<Order> ListOrders = AddInHelper.GetSelectedOrders();
                var shipmentLabelsReq = Context.Current.Request["shipmentLables"];
                var returnLabelsReq = Context.Current.Request["returnLables"];

................................

 

The shipmentLabReq and returnLabelReq null. I can't get the data from the form? Any suggestions?

 
Daniel Hollmann
Reply

I also have another problem.

I would really like to have some info about the selected orders, in my dialog.. But I can’t seem to find any way to do that. The dialog is rendered on load where there are no selected orders yet. Is there a clever way to get data on the selected orders in the dialog script that is rendered on button.OnClientClick?

 
Nicolai Pedersen
Reply

Hi Daniel

You will have to look at the post back data. It sounds like you are on a list of orders - and the checked list changes. So you can read them either with javascript when you display the dialog or in the postback when submitting the content of your dialog.

Happy coding!

Nicolai

 
Daniel Hollmann
Reply

Hi Nicolai and thanks for your answer.

I found a way to display the data using Javascript in the form, but when I submit I can't catch the
postback in a method, which is the origin of my problem...
The click method does not trigger, unless the "EnabledServerClick" is set to true, which then triggers simultaneously with the client onClick method

Any ideas on how I can catch the submit a form without having the EnabledServerClick set to true?

 

Daniel

 
Nicolai Pedersen
Reply

Will you not be able to just use Request.Post? Instead of the asp.net built in thingie.

 
Daniel Hollmann
Reply

I haven't been able to, since my submit does not hit any of my code :/ 

I am really looking for a good example on how to implement a AddIn button with a dialog and then a post back, but I can't find anything :/ 

Can you point me to some doucmentation?

And yes I'm implemention a AddIn on the orderlist

   [AddInTarget(RibbonBarAddInTarget.eCom.OrderList)]

 

You must be logged in to post in the forum