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.
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");
}