Getting "defaultValue" for a module setting?

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
2/10/2011 1:19:13 PM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Getting "defaultValue" for a module setting?

Hi everyone, I'm working with some module settings. The documentation on the Module Settings page is great, and covers loading a stored setting value, but in my current project, I'd also like to grab the default value that's specified for a setting ("defaultValue" in the config file), so I won't have to separately hardcode those values in the code for comparison. Is that value even available at runtime? If so, can anyone help with some code to do that?

Thanks!

Jamie

2/10/2011 1:33:41 PM
Gravatar
Total Posts 18439

Re: Getting "defaultValue" for a module setting?

Hi Jamie,

Default settings are updated from the feature definition file every time you visit the setup page, so if you add new settings they also get created with their defaults when you visit the setup page. Once an instance of a feature is created the instance settings are used, the default settings are only for when creating new instances or when a new setting is added, then the next time you visit the module settings page for the instance it will get the default setting.

Most features now have a FeatureConfiguration class that encapsulates the settings, so typically the defaults are hard coded both in the feature definition and in the FeatureConfiguration so that if the setting has not yet been created for the instance it uses the default value.

For example the Image Gallery has the class GalleryConfiguration.cs

default values are setup like this:

private bool useSlideShow = false;

public bool UseSlideShow
{
    get { return useSlideShow; }
}

then in the constructor for the GalleryConfiguration, the hashtable of settings are passed in and if the instance setting exists it replaces the default value

useSlideShow = WebUtils.ParseBoolFromHashtable(settings, "UseSilverlightSlideshow", useSlideShow);

So for most features if we add a new setting then we also update the FeatureConfiguration class

Once a feature has more than a couple of settings this FeatureConfiguration class helps keep things simple and helps us keep the code for parsing the settings out of the hashtable in one location.

So for example in the Gallery.ascx.cs we pass the settings hash table into the constructor of the FeatureConfiguration like this:

config = new GalleryConfiguration(Settings);

then we can just use config.PropertyName to get at the settings and it will always either have the default or the value saved for the instance if the instance has been saved since the new setting was added.

Hope it helps,

Joe

 

2/10/2011 2:33:48 PM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Getting "defaultValue" for a module setting?

Thanks for that detailed explanation, Joe! It makes sense that the config file settings would just be used in the initial settings setup. I know my case is a little special, because my settings are going to be used in JavaScript, and if they are equal to the library's default value I don't want to include them in the output, to preserve a little bit of bandwidth and possibly give better performance. I'll go ahead and duplicate those defaults in some constants where I'm gathering the settings values.

Jamie

You must sign in to post in the forums. This thread is closed to new posts.