Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using ASP.NET Web Forms without WiFi
Message
 
 
À
26/11/2015 12:25:09
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01627849
Message ID:
01627930
Vues:
34
>>>>>>>Yes - I knew we'd have to allow offline working from the word go so use very little ASP.NET functionality. The pages are all static HTML. The server only has to deliver those pages and send/receive data via WebApi. All of the UI state is handled in angularjs. If you are relying on round trips to the server to update the UI then you will have a real problem. If you can then focus on just those page which *must* work offline and convert them to static pages with local storage.
>>>>>>
>>>>>>If you don't mind, I have a question. In my application in order to update the database the pages call SQL Stored procedures. When you are using WebApi, how do you update the SQL Server (or whatever database you are using)? I mean, conceptually, does WebApi call Stored procedure or the client WebApi updates the server?
>>>>>
>>>>>I see Craig's provided an answer. Basically WebApi simply responds to HTTP requests by sending .NET objects (which can be complex) back to the client - in your case a browser in which case converting them to JSon objects makes sense (WebApi can do that for you automatically.)
>>>>>
>>>>>Behind that you will need another layer on the server which will retrieve data from SQL and convert it to suitable objects and which will update the SQL DB from data returned by the browser where necessary. This is where Entity Framework shines - it can do all that work for you. If you don't want to use it then the approach we talked about earlier (or Rob's suggestion) can work. My experience is that EF is simple to set up if you are working against a stable DB structure - but can get hairy if the DB design itself is in a state of flux.
>>>>>
>>>>>On the client you can make calls to WebApi using XMLHttpRequest or, maybe better, use the angularjs $https service (or the higher level $resource service). The advantage of angularjs is that it can update the DOM automatically when data is received (basically acting as a MVC/MVVM type controller on the browser).
>>>>>
>>>>>If you want to give me an example DB table I could probably knock up a concrete example for you....
>>>>
>>>>Thank you for detailed explanation. Clearly you are light years ahead of me, as far as using all the current-day technologies.
>>>>
>>>>But I ran into another issue that I am not sure how to resolve. Again, working on making my drop-down boxes of ASP.NET pages in a disconnected mode. I can save the dataset to localStorage (by way of serializing it to JSON). But how do I get the dataset from the localstorage at run time? As I said before, my aspx pages drop-down controls are bound to dataview/dataset in the LOAD method of the page. So there is a need to make a trip to the server. But in the disconnected state, the page cannot load anything from the server.
>>>>
>>>>So the only thing I am thinking is to change from ASP.NET to plain HTML page. But then I have no idea how HTML page "gets" the data from the localStorage and populates the drop-down control. Do you think Javascript (or jQuery) has functions to get JSON from a localStorage and convert to the something that can be used in drop-down control?
>>>
>>>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
>>
>>Thank you very much for the code. I will try it. I could not help noticing your commented "call to WebApi"; so here is another question. You can make call to WebApi from javascript?
>
>The example code I sent a couple of days ago shows how it is done in angularjs. If your not using that then this might be an extended example of the code I posted earlier:
    <script type="text/javascript">
>        document.addEventListener("DOMContentLoaded", function (event) {
>            if (!navigator.onLine) {
>
>                var customers = JSON.parse(localStorage["Customers"]);
>                populateDropDown(customers);
>
>            } else {
>                var xReq = new XMLHttpRequest();
>                xReq.addEventListener("load", dataReceived);
>                xReq.open("GET", "/customers");
>                xReq.send();
>            }
>        });
>
>        function dataReceived() {
>            var customers = JSON.parse(this.response);
>            populateDropDown(customers)
>        }
>
>        function populateDropDown(customers) {
>            var theDropDown = document.getElementById("myDropDown");
>            for (var i = 0 ; i < customers.length; i++) {
>                var option = document.createElement('option');
>                option.text = option.value = customers[i].Name;
>                theDropDown.add(option, 0);
>            }
>        }
>    </script>
>
>>As to your comment about beauty of angular :), it is all in the eyes of the beholder :)
>
>I guess you need to behold it for a while :-} Haven't touched on the other functionality in there such as
>Two-way data binding.
>Directives.
>UI-Router
>Etc.

Thank you very much. A lot to learn for me.
"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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform