Step 1 | Step 2 | Step 3.1 Step 3.2 Step 3.3 |
Step 4.2
Clothing - Using DATA attribute initialization and loading the label internal
cache data separately.
Load data: |
Load state: ...
|
---|---|
Data record | Printing |
Read below first! |
This example is much like 3.2 but here we load the data pointing an ASP page on the server side. We pass a parameter to the page and it extracts the requested data entries and Active Label loads them into its internal cache. In fact we are using the same ASP page like in 4.1 (but we pass only one parameter to it here, of course there is no problem to pass both).
So this page like 3.2 loads a label file which contains the label design, the data fields definition, but no data. Then we request the data separately - in this case an user action on the client side invokes the operation. You can choose which items you want and click Load data. The onClick event handler for the button will clear the internal cache and then send the request, by using the the MergeSrc method of the VisiLabel object.
The asynchronous nature of what we do here rises a question. In the example the user invokes the request to the server in result of which the data will be loaded into the label. This can be done otherwise of course - for example on page load, from another frame and so on. However in all those cases we will want to know the same - when the data load completes and how to understand if it was successful.
There are other examples especially dedicated to the VisiLabel events, but we handle one event here to do that job. We handle the event OnDownloadCompleted. It fires after each download operation - when it completes. Furthermore we use also the ObjectState property to query the current state of the object.
The event: To handle the event of the VisiLabel ActiveX on the page we use this kind of code:
<SCRIPT FOR
="VisiLabel" EVENT="OnDownloadCompleted(element,success)">
if (element == -1) {
if (!success) {
alert("An error occurred while attempting to download data");
} else {
alert("Data has been loaded successfuly - you can navigate and print now");
}
}
ShowState();
</SCRIPT>The construction is an Internet Explorer standard feature. Perhaps the usage of event with 2 parameters is not so frequent, but aside of that there is nothing unusual in this. The parameters, however, are important. The VisiLabel ActiveX fires all the events even those related to the internal objects (for example you can invoke reload operation over an image element - the event that marks the completion will be fired by the VisiLabel object and not by the Image object). So, the first parameter element informs you about the index of the element for which the event is. As the internal elements have 0-based indices -1 means the VisiLabel object itself (i.e. the root object in the VisiLabel object hierarchy). Therefore in the event handling code we explicitly check for this.
The second interesting point is the ObjectState property (open the page in a text editor and see the Javascript in it - all the code is before the comments). The button "Check state now" checks this property and sets a text corresponding to its value on the page. As you will notice looking at the script there is a value 4 (Ready) and value 3 (loaded with problems). You will notice that "loaded with problems" is displayed when you load the data. We could have avoided this, but it is important to show the specifics. This property returns the overall state of the ActiveX and not only the state of the root object. That is why you do not see Ready at first - the image which is supposed to be loaded when the data is applied is not loaded yet, thus the overall state of the entire ActiveX is not completely ok. Now, after loading the data, if you click Reset (or Navigate to a valid record with one of the other buttons) the image will be loaded and the state will change to Ready as an image is loaded where it is supposed to be. Thus be careful when using ObjectState over the root (VisiLabel) object, do not forget that it indicates the overall state in contrast to the property with the same name of the graphical obejcts.