How to get a variable from my settings.js file in to my gadget.js file

Answered How to get a variable from my settings.js file in to my gadget.js file

  • Wednesday, November 25, 2009 10:39 AM
     
     

    I am trying to develop a database driven Windows 7 Gadget and the settings page has multiple filters. I have captured the selected values in the drop down(select) and trying to pass these values to the query in the Gadget.js file upon clicking the OK button in the settings page.
    i have tried using


    System.Gadget.Settings.Writestring("SN", SNValue); in the settings.js file and

    var S = System.Gadget.Settings.readString("SN"); in the gadget.js file.


    basically i would like to use the "SN" in Gadget.js file.

    please let me know where i am going wrong..

    Thanks in advance.

     


    RamukNarik

All Replies

  • Wednesday, November 25, 2009 10:53 AM
     
     Answered Has Code

    I don't know if this is just a mistake in your question, but you have a problem with your use of the writeString method:

    System.Gadget.Settings.Writestring("SN", SNValue); // there is no Writestring method
    System.Gadget.Settings.writeString("SN", SNValue); // this is correct

    If that doesn't help then without seeing more code I can only really offer you the following advice:

    • Don't confuse System.Gadget.onSettingsClosing with System.Gadget.onSettingsClosed.  System.Gadget.onSettingsClosing would be used in settings.js to write the "SN" setting and System.Gadget.onSettingsClosed would be used in gadget.js to read the "SN" setting.  I ran into this when I first started out in gadget development.
    • As well as writing the setting, you could call the function you want to use directly from the settings.js using System.Gadget.document.parentWindow.functionName(SNValue).

    I hope that helps.

    Andy

    • Marked As Answer by GopalKiran Thursday, November 26, 2009 9:36 AM
    •  
  • Thursday, November 26, 2009 3:51 AM
     
      Has Code
    Hi Andy,

    Thanks for your quick response. As you pointed, i had used Writestring method instead of writeString and it was my mistake. But even then after correcting it i am not able to pass the value from the settings page to gadget upon clicking the OK button. I will try to post the sample code later by EOD to clearly illustrate what i am doing.
    As you said, i was also initially confused about  the System.Gadget.onSettingsClosing with System.Gadget.onSettingsClosed but later read about them and used accordingly.

    Before that, can you please clarify me what does "name of the settings key" mean...

    Syntax

    System.Gadget.Settings.writeString(strName, strValue)

    Parameters

    strName Required. String that specifies the name of the Settings key.
    strValue Required. The String value to store.
    Thanks for your clear explanation.


    RamukNarik
  • Thursday, November 26, 2009 9:40 AM
     
     

    Hi Andy,

    Thanks for your response. I am able to pass the values from the settings page to Gadget page. Used your above inputs and fixed other issues in my code. Still facing some other issues. Will try to fix them too and will take your help if required.

    Thanks!


    RamukNarik
  • Thursday, December 17, 2009 3:28 AM
     
     
     You can customize the name 
     For example, variables with representatives of significance : 
  • Wednesday, March 28, 2012 11:48 AM
     
     

    I am developing a gadget. After setting values in settings html page, after i click the ok button, settings page values are not reflected in the gadget page....I need to apply the settings value immediately after the settings page is closed. How can I do this?


    here is my code


    This is main page


    <script>

     
    System.Gadget.settingsUI = "Settings.html";   
      System.Gadget.onSettingsClosed = settingsClosed;
    function settingsHaveChanged(varText,NodeName,TagName,FieldName,RefTime)
    {
    mtagname=TagName;
    mfieldname=FieldName;
    d=RefTime;
     }
     


    Settings page   

    System.Gadget.onSettingsClosed = SettingsClosed;

    function SettingsClosed(event)
    {
        // User hits OK on the settings page.
        if (event.closeAction == event.Action.commit)
        {
    System.Gadget.document.parentWindow.settingsHaveChanged(,tagName,fieldName,d);
     userEntry = document.getElementById("valueOfTag").value;
    mtagname= document.getElementById("tagName").value;


    mfieldname= document.getElementById("fieldName").value;

    d=document.getElementById("updateInterval").value;
        
        

            
        }
        // User hits Cancel on the settings page.
        else if (event.closeAction == event.Action.cancel)
        {
            SetContentText("canceled");
        }
        
    }

    please help me in how to get input values from setting page to main page