Implementing deep-linking with existing multi-form structure
Fixity uses a WiseJ Page as its main starting point, from which point it opens multiple Forms using ShowDialog().
Each of these forms has a form ToolButton back button, with its own code. (usually .dialogResult = Cancel + close, but sometimes with extra code like confirmation dialog, “do you want to save changes”, etc)
One of the issues with a mobile SPA is making use of the back button — avoiding closing the web app, and instead navigating “back” in the app.
So what I would like to do, is upon detection of back button (“hash changed”), close the active Form that is showing.
Sometimes there are nested levels of forms with ShowDialog showing.
Sometimes the app is called by a URL with parameters (?issue=1) to tell Fixity where to go and what to do — I’d need to make that loading behavior line up with Hash behavior (#editissue=1)
Where to place a Application.HashChanged event in a singular location? In Program.vb?
How can I identify the active form? Would it by checking the “last” hash? I.e, if the previous has was “#editissue=123” then we know it is frmEditIssue that needs closing.
Then could I use something like Application.OpenForms(frmEditIssue).BackButtonCode() to simulate the back button? (public method on each form)
I could set Application.Hash = “FormImAboutToOpen” prior to opening each new Form, but that would trigger ApplicationHashChanged, and I’d need a way to distinguish the opening of a form, vs hitting back button.
I suppose I could implement a global function SetHashForNewForm() that removes the handler, sets the hash, and then reattaches the handler, and call it just prior to calling .ShowDialog() on all my forms.
Does this approach make sense to you? Suggestions?
Assuming it works, the considerations for then dealing with the app initialization code (currently using Application.QueryString()) to instead read the passed-in hash (via URL) would be a whole other ball of wax…
2. How can I identify the active form? Would it by checking the “last” hash? I.e, if the previous has was “#editissue=123” then we know it is frmEditIssue that needs closing.
You can get a list of all open Forms using Application.OpenForms. There is no concept of “active Form” since you can open several modeless forms at the same time. You must “design” your own way of storing it. You can use a session variable to store something unique about the “active form”. To get the form instance, you can iterate Application.OpenForms to find the relevant form.
3. Then could I use something like Application.OpenForms(frmEditIssue).BackButtonCode() to simulate the back button? (public method on each form)
Once you iterate Application.OpenForms and find the relevant form instance, you can call internal or pubic (Friend or Public in VB) methods, provided you cast your form to the appropriate base class or interface.