Domanda

Best way to get from a custom action js command an webconfig appsetting key value, or another similar approach. ideas?

thanks.


Reference a .js file on a custom action elements.xml

on my javascriptmethods.js file:

    function test(){
      alert('test message.');}

on my custom action elements.xml:

<CustomAction
    Location="ScriptLink"
    ScriptSrc="/_layouts/.../javascriptmethods.js" Sequence="100">


<CommandUIHandlers>
   <CommandUIHandler Command="MyCommands.Alert"
   CommandAction="javascript:test();" />
</CommandUIHandlers>

what's missing?

È stato utile?

Soluzione

For security reasons, you cannot access the web.config settings from javascript so the best approach would probably be to write a custom control / web part that can read the setting and then write it into the page into a script block.

Altri suggerimenti

I wouldn't necessarilly rely on <appSettings> in SharePoint applications, mostly for things that are going to appear on the UI, or that should be easily configurable within the application.

Instead, would use some kind of Configuration Store approach, where you save the Key/Value setting in a List within SharePoint UI (such as SiteConfiguration).

Then, you can easily access the value using the javascript client object model.

Example config store: http://spconfigstore.codeplex.com/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top