Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using ASP.NET Web Forms without WiFi
Message
 
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01627849
Message ID:
01628015
Views:
44
>>>
>>>Use regular JavaScript (but, compared to angular it's ugly). Something like:
<script type="text/javascript">
>>>        document.addEventListener("DOMContentLoaded", function (event) {
>>>            if (!navigator.onLine) {
>>>                var theDropDown = document.getElementById("myDropDown");
>>>                var customers = JSON.parse(localStorage["Customers"]);
>>>                for (var i = 0 ; i < customers.length; i++) {
>>>                    var option = document.createElement('option');
>>>                    option.text = option.value = customers[i].Name;
>>>                    theDropDown.add(option, 0);
>>>                }
>>>            } else {
>>>                // Either make call to WebApi on the server for the data
>>>                // Or assume the page was loaded from ASP.NET and the select is already populated.
>>>            }
>>>        });
>>>    </script>
(Assuming a 'select' element in the markup with id="myDropDown" and that you are sure the data is in local storage)
>>>
>>>But ideally you would always handle the layout in JavaScript whether the data is obtained from the server or you are using local storage
>>
>>Me again :). Could you, please, suggest why the following string in the localStorage, when retrieved with JSON.Parse() gets 0 (zero) length?
>>
>>
>>{"Table":[{"BUILDING":"MAIN-LV1 ","BLD_DESCR":"MAIN-LV1      Main Building "},{"BUILDING":"WWTP-LV ","BLD_DESCR":"WWTP-LV       WASTE WATER TREATMENT PLANT "},{"BUILDING":"ALL-LV ","BLD_DESCR":"ALL-LV        ALL "}]}
>>
>>
>>This is how I get the value from the localStorage:
>>
>>
>> var buildings = JSON.parse(localStorage["buildings"]);
>>
>>
>>Then in the javascript I check the length of the object buildings and it is 0 (zero).
>
>'buildings' is an object containing the 'Table' array. Try 'buildings.Table.length'

You are correct. I changed my code from serializing dataset to serializing datatable. So now the string in the localStorage is:
[{"BUILDING":"MAIN-LV1 ","BLD_DESCR":"MAIN-LV1      Main Building "},{"BUILDING":"WWTP-LV ","BLD_DESCR":"WWTP-LV       WASTE WATER TREATMENT PLANT "},{"BUILDING":"ALL-LV ","BLD_DESCR":"ALL-LV        ALL "}]
Now the object/var 'buildings' has a length of greater than zero. And I am beginning to see the light.

(P.S. yesterday I was going through a course on WebApi; today I am planning on started to learn more about EF as I think that WebApi with EF is not of much use).
Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform