简体   繁体   中英

Simple desktop gadget won't save its data between runs

I'm trying to write a very simple Windows 7 gadget, which is easy enough. But I can't get any of the data I'm saving with System.Gadget.Settings.write/read ( writeString / readString ) to persist between runs of the gadget. I know it can be done, because all the other Microsoft gadgets do it. I'm obviously missing something crucial, but can't see it.

This is a very simple cut down example:

<html>
<head>
<meta http-equiv="MSThemeCompatible" CONTENT="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=Unicode" />
<title>test</title>
    <script type="text/javascript">
        function save() {
            var e = document.getElementById("name");
            if (e && e.value) {
                System.Gadget.Settings.write("name", e.value);
                prompt("turnedout", System.Gadget.Settings.read("name"));
            }
        }

        function load() {
            var t = System.Gadget.Settings.read("name");
            prompt("turnedout", t);
        }
    </script>
</head>
<body scroll="no" unselectable="on" onload='load()'>
    <label for='name'>Name</label>
    <input id='name'>
    <input type="button" value='Save' onclick='save()' />
</body>
</html>

I've traced through the code and everything appears to go in the right places. What's missing?

Even I had the same issue, but when I moved the System.Gadget.Settings.write("name", e.value); to the html which is specified in the gadget.xml file, it wrote to the settings.ini file properly

Gadgets don't work like desktop applications with regard to settings. The settings are per instance of a gadget. Close the instance and you lose the settings. There are other limitations as well. There's a good explanation at: http://dotnetslackers.com/articles/net/SettingsManagerforWindowsVistaSidebarGadgets.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM