Form Tips - Forcing a Form.Load event to fire when coming back to same form

From Visual WebGui Wiki

Jump to: navigation, search

Contents

Overview

Think of a scenario where you have two forms in your application, Form1 and Form2. You register a Form1.Load and Form2.Load event handler, where you do some initializing necessary for your form. You open your browser and open Form1.wgx and you get Form1.Load event firing and do it's work. Now you redirect to Form2.wgx (changing browser's address bar for instance) and you get Form2.Load event firing. Finally you redirect back to Form1.wgx, and your Form1.Load event does not fire in that case.

The reason lies in the fact that when you come back to Form1, you are within the same session and there is allready a Context available for Form1 (provided you come back within the timeout limits), so no new context is created and hence no Load event is fired, as it fires a part of a new Context being created.

Possible solutions

Detecting when you go to another page

By registering to the Application.ThreadSuspend event, you can make sure you destroy the Context of Form1 before leaving it.

Samples of use

Making your form stateless

By making the Form requiring the Load event to be fired as stateless, you will force the Load event to fire every time it is visited. A testing is recommended in this case as this might have complications.

Forum Threads

Issues

Using vwginstance and an instance counter

Samples of use

Redirecting with unique query strings

By redirecting to the new form and make each redirect use a unique query string, you will force the Form.Load event to fire every time. The redirect could for instance be of the form http://someapp?requestid=xxx where you make sure xxx is a unique number.

A special case of using a unique query strings would be to use the "vwgInstance" query string variable. The value of this parameter is numeric and begins with the value "1" which is the default.
Every consecutive new context that is opened on the session gets a number that is inceremented by 1. This will not only force the Load event to fire, but will create a new context that your form will run in.

Forum threads

Issues

References

Articles

Personal tools