Call C# method from JavaScript in browser Control

Add-in Express™ Support Service
That's what is more important than anything else

Call C# method from JavaScript in browser Control
 
shyam shah shah


Guest


I am using Addin Express for developing Com Addin for Outlook. It has several ADXOlForm instances. I Tried to set load html text dynamically in webbrowser. When the window.external.{a method} is called . It throw error and not redirect to other page.
My current code is

I am displaying in same window . Following is my source code. I want to display webrowsercontrol in ADXOlFormSidePane form.


public ADXOlFormSidePanel()
{
InitializeComponent();

pictureBox1.Visible = false;
webBrowser1.AllowWebBrowserDrop = false;
webBrowser1.IsWebBrowserContextMenuEnabled = true;
webBrowser1.WebBrowserShortcutsEnabled = true;
// ADXOlFormSidePanel sidePanel = AddinModule.CurrentInstance.adxOlFormsCollectionItem1.FormInstances(0) as ADXOlFormSidePanel; // it is recognize here 0 is index of sidepanel form in form manager.

webBrowser1.ObjectForScripting = this;
this.webBrowser1.Navigate("about:blank");
HtmlDocument doc = this.webBrowser1.Document;
doc.Write(String.Empty);
if (string.IsNullOrEmpty(VeloxyConfig.Token))
{
this.webBrowser1.DocumentText = Properties.Resources.Login;
}

}
[CODE]

I am waiting for help.
Posted 25 Oct, 2016 09:13:43 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Shyam,

I've created a new Outlook add-in project, added an Outlook Forms Manager, added an ADXOlFrom, dropped a WebBrowserComponent on it, added the html you sent me to the resource called "Login", and wrote the following event handler of the ADXOlForm.ADXAfterFormShow event:

        private void ADXOlForm1_ADXAfterFormShow() {
            webBrowser1.AllowWebBrowserDrop = false;
            webBrowser1.IsWebBrowserContextMenuEnabled = true;
            webBrowser1.WebBrowserShortcutsEnabled = true;
            webBrowser1.ObjectForScripting = MyAddin183.AddinModule.CurrentInstance;
            this.webBrowser1.Navigate("about:blank");
            HtmlDocument doc = this.webBrowser1.Document;
            doc.Write(String.Empty);
            this.webBrowser1.DocumentText = Properties.Resources.Login; // HTML file is reading from  Resource
        }


Note the value I assign to the ObjectForScripting property: it is a reference to the instance of the add-in module which is loaded in Outlook.

In accordance with the code of the javascript that the html page invokes, I put the following method on the module:

        public void LoginToServer() {
            MessageBox.Show("It works", this.AddinName);
        }


When the webBrowser component on the pane shows the HTML page and I click the corresponding HTML control on the page, the LoginToServer() method above is invoked.


Andrei Smolin
Add-in Express Team Leader
Posted 27 Oct, 2016 04:30:57 Top