Webpage in dashboard

Okay, I have made progress. I have the webpage populating when I hard code the value.

		private void SetupBrowser()
                {
				wbSite = new System.Windows.Forms.WebBrowser();
				wbSite.Dock = System.Windows.Forms.DockStyle.Fill;
				wbSite.Location = new System.Drawing.Point(0,0);
				wbSite.MinimumSize = new System.Drawing.Size(20,20);
				wbSite.Name = "wbSite";
				wbSite.Size = new System.Drawing.Size(560,323);
				wbSite.TabIndex=0;
				wbSite.WebBrowserShortcutsEnabled = false;
				wbSite.IsWebBrowserContextMenuEnabled = false;
				wbSite.ScriptErrorsSuppressed = true;
				grpboxQuickNotes.Controls.Add(wbSite);
				//custnum = epiTextCustNumReference2.Text;
				custnum = "24989";
				wbSite.Navigate("http://envisionpp/test/callLogViewer.asp?custnum=" + custnum.ToString()); 
                                
                }```

However, I don't want to hard code the value I want the line that is commented out: //custnum = epiTextCustNumReference2.Text to feed the website browser with the customer number.

Where is the epiTextCustNumReference2 coming from? I’m trying to figure out what you need to do to get it to work.

what happens if you don’t use custnum at all and just use epiTextCustNumReference2.Value.ToString() ?

epiTextCustNumReference2 is the text box that contains the value I need to pass into the webpage. It contains the customer number.

When I just try to put in epiTextCustNumReference2.ToString(); nothing happens. Do I need to have the webpage refresh maybe after I enter a value in that text box. I tried doing the Refresh all after I enter a number in there but it doesn’t work.

did you add .Value ?

No, it is actually a text box. Not a numberic editor. Do I still need to do .Value?

I don’t know, but try it. I’m shooting in the dark a little. I’ve needed to do it in the past.

wbSite.Navigate("http://envisionpp/test/callLogViewer.asp?custnum=" + epiTextCustNumReference2.Value.ToString());

That doesn’t work it causes an error when I launch: Exception has been thrown by the target of an invocation.

If you just do a message is the text reading correctly?

MessageBox.Show(epiTextCustNumReference2.ToString());

or just a message box with the custnum MessageBox.Show(custnum);

Is this a typo? does it compile with this?

Never mind, that’s your own variable. (I’m trying too hard…)

It compiles with that. I;m adding Message Box Now and will let you know.

It doesnt return the right information and it does it right at launch of dashboard. I need to be able to enter a number in that text box and then refresh and have it go get the correct webpage.

So you’ll have to find a different event to hang it off of. I would think an, “after field change” on that text box would be what you want for that one. I don’t know how the web page stuff works, but I would imagine that you need the set up stuff where you have it, and then just move the navigate to the after field change event.

I tried that…ugh. I think I’m just gonna make it its own dashboard and attach that to the sheet. I give up…

Are you calling the SetupBrowser() method every time you’re trying to change the displayed page? That could definitely be part of the problem. The WebBrowser control only needs to be instantiated once (in the class), initialized once (usually in InitializeCustomCode()), and then subsequent navigation calls are just wbSite.Navigate() on some sort of event. Go ahead and remove the wbSite = new WebBrowser() line from the SetupBrowser() method. The web browser is dynamic and will start loading the new site immediately without having to clear anything out - just like typing in a new URL and pressing Enter in an external browser.

What @Banderson said is spot on. You’ll need to identify an event that correlates to when the number changes and then call wbSite.Navigate(“http://envisionpp/test/callLogViewer.asp?custnum=” + epiTextCustNumReference2.Text) with the new customer number. Finding that event can sometimes be a frustrating process of trial-and-error with MessageBoxes, but you do get there eventually.

Thanks for this code, I used it successfully in my code with a variable URL. However, is it possible to add a toolbar to this so I can use the functions goBack or goForward or refresh?

I’m not sure what I should change to include some buttons there:

EDIT:
I added this but not sure how to add a toolbar now:
browserDisplay.Dock = System.Windows.Forms.DockStyle.Bottom; // it was ‘Fill’ before
browserDisplay.Location = new System.Drawing.Point(0, 40);

Glad to see you’ve got the placement figured out. I’ve never needed to add a toolbar, but you should be able to put an EpiButton control in that space and trigger the browser’s GoBack() or GoForward() method on a click event.

Yep, I figured it out too, surprisingly easy! I added this code:

ToolStrip mainToolBar = new ToolStrip();  
		mainToolBar.Size = new System.Drawing.Size(400, 40);
		//create previous button
		ToolStripButton buttonPrevious = new ToolStripButton();
		buttonPrevious.Text="Previous";
		buttonPrevious.Click += new System.EventHandler(buttonPrevious_Click);
		//create forward button
		ToolStripButton buttonForward = new ToolStripButton();  
		buttonForward.Text = "Forward";
		buttonForward.Click += new System.EventHandler(buttonForward_Click);
		//create refresh button
		ToolStripButton buttonRefresh = new ToolStripButton();  
		buttonRefresh.Text = "Refresh";
		buttonRefresh.Click += new System.EventHandler(buttonRefresh_Click);
		// add buttons to toolbar
		mainToolBar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            buttonPrevious,
            buttonForward,
			buttonRefresh
		});

Now, I just need to add the epicor icons (refresh icon) on my buttons, don’t know how to find them ! :wink:

1 Like

I did get this working. Does anyone know how I would trigger an event on the browser close. I have this so far

//Launch Epicor URL - Any Area
	private void LaunchURL(string url, string title = "", int padding = 65)
	{
	Ice.Lib.Customization.CustomWebBrowserDialog uiWebBrowser = new Ice.Lib.Customization.CustomWebBrowserDialog();
	Ice.Lib.Framework.EpiBaseForm f = (Ice.Lib.Framework.EpiBaseForm)csm.PersonalizeCustomizeManager.TopControl.FindForm();
   uiWebBrowser.Width = f.Width - padding;
   uiWebBrowser.Height = f.Height - padding;
   uiWebBrowser.Text = title;
   uiWebBrowser.HomeURL = url;
   uiWebBrowser.StartPosition = FormStartPosition.CenterScreen; // If you don't center you can use .Top and .Left
   uiWebBrowser.Show();
   uiWebBrowser.OnRefresh(); // Loads URL
//	if (uiWebBrowser.Close)
//	{
//	RefreshAfterClose();
//}
//	
//}
//
////Order - Refresh After Close
//private void RefreshAfterClose()
//{
//MessageBox.Show("Window Closed");
//}

I’m sure there’s a better way to code this but this is how I got something working.

I didn’t find an event handler for the CustomWebBrowserDialog, but there’s the windows form handler FormClosed.

Try this:

    private void LaunchURL(string url, string title = "", int padding = 65)
    {
        Ice.Lib.Customization.CustomWebBrowserDialog uiWebBrowser = new Ice.Lib.Customization.CustomWebBrowserDialog();
        Ice.Lib.Framework.EpiBaseForm f = (Ice.Lib.Framework.EpiBaseForm)csm.PersonalizeCustomizeManager.TopControl.FindForm();
        uiWebBrowser.Width = f.Width - padding;
        uiWebBrowser.Height = f.Height - padding;
        uiWebBrowser.Text = title;
        uiWebBrowser.HomeURL = url;
        uiWebBrowser.StartPosition = FormStartPosition.CenterScreen; // If you don't center you can use .Top and .Left
        uiWebBrowser.Show();
        uiWebBrowser.OnRefresh(); // Loads URL

        // This is what probably should be moved somewhere else.
        uiWebBrowser.FormClosed += UiWebBrowser_FormClosed;
    }

    private void UiWebBrowser_FormClosed(object sender, FormClosedEventArgs e)
    {
        MessageBox.Show("web browser closed");
    }

Hello, just wondering how did you make a parameter pass and feed the URL with that value.

Thanks