Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7027487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:15:15+00:00 2026-05-28T00:15:15+00:00

This is a code block I use in most of my DNN Settings modules

  • 0

This is a code block I use in most of my DNN Settings modules but it seems too verbose for what it does. How would you condense this to make it more usable or at least less redundant?

    /// -----------------------------------------------------------------------------
    /// <summary>
    /// LoadSettings loads the settings from the Database and displays them
    /// </summary>
    /// -----------------------------------------------------------------------------
    public override void LoadSettings()
    {
        try
        {
            if (Page.IsPostBack == false)
            {
                ddlTreeTabId.DataSource = GetTabs();
                ddlTreeTabId.DataBind();
                if (!string.IsNullOrEmpty((string)TabModuleSettings["TreeTabID"]))
                {   //Look for the tree tab id
                    this.ddlTreeTabId.SelectedValue = (string)TabModuleSettings["TreeTabID"];
                    //If we're here, we have a tab module id, now we can grab the modules on that page
                    LoadTabModules(ddlTreeModuleID, int.Parse((string)TabModuleSettings["TreeTabID"]));

                    //we only do this part if the proceeding steps checked out
                    //if we have a tree module id 
                    if (!string.IsNullOrEmpty((string)TabModuleSettings["TreeModuleID"]))
                    {
                        try
                        {
                            //carefully try to select that item from the module id drop down list
                            this.ddlTreeModuleID.SelectedValue = (string)TabModuleSettings["TreeModuleID"];
                        }
                        catch (Exception ex)
                        { //There may have been a module id but it aint on that page any more.  Ignore the error.
                            // I hate invoking try just to ignore an error. seems wasteful.
                        }
                    }
                }
        }
        catch (Exception exc) //Module failed to load
        {
            Exceptions.ProcessModuleLoadException(this, exc);
        }
    }

My ideal solution would implement the properties in such a way that throughout the module a Tree Module ID can be returned without typing all this.

if (!string.IsNullOrEmpty((string)Settings["TreeTabID"]) &&
    !string.IsNullOrEmpty((string)Settings["TreeModuleID"]))
{
    Do_SomethingWithTheIDs(
        int.Parse((string)Settings["TreeTabID"]), 
        int.Parse((string)Settings["TreeModuleID"]));
}

Imagine the complexity of loading several modules like that. Ugh.


UPDATE

Thanks to Olivier, I’ve wrote a new class to manage the properties

public class TreeSettingsBase : ModuleSettingsBase
{
    public int? TreeTabID
    {
        get
        {
            string s = (string)Settings["TreeTabID"];
            int id;
            return Int32.TryParse(s, out id) ? id : (int?)null;
        }
    }

    public int? TreeModuleID
    {
        get
        {
            string s = (string)Settings["TreeModuleID"];
            int id;
            return Int32.TryParse(s, out id) ? id : (int?)null;
        }
    }

    public int? PersonTabID
    {
        get
        {
            string s = (string)Settings["PersonTabID"];
            int id;
            return Int32.TryParse(s, out id) ? id : (int?)null;
        }
    }

    public int? PersonModuleID
    {
        get
        {
            string s = (string)Settings["PersonModuleID"];
            int id;
            return Int32.TryParse(s, out id) ? id : (int?)null;
        }
    }
}

So now my LoadSettings looks like this:

public override void LoadSettings()
    {
        try
        {
            if (Page.IsPostBack == false)
            {
                ddlTreeTabId.DataSource = GetTabs();
                ddlTreeTabId.DataBind();               
                if (TreeTabID.HasValue)
                {   
                    this.ddlTreeTabId.SelectedValue = TreeTabID.ToString();
                    LoadTabModules(ddlTreeModuleID, TreeTabID.Value);
                    if (TreeModuleID.HasValue)
                    {
                        try
                        {
                            this.ddlTreeModuleID.SelectedValue = TreeModuleID.ToString();
                        }
                        catch (Exception ex)
                        { 
                        }
                    }
                }
                ddlPersonTabId.DataSource = GetTabs();
                ddlPersonTabId.DataBind();
                if (PersonTabID.HasValue)
                {
                    this.ddlPersonTabId.SelectedValue = PersonTabID.ToString();
                    LoadTabModules(ddlPersonModuleID, PersonTabID.Value);
                    if (PersonModuleID.HasValue)
                    {
                        try
                        {
                            this.ddlPersonModuleID.SelectedValue = PersonModuleID.ToString();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }

            }
        }
        catch (Exception exc) //Module failed to load
        {
            Exceptions.ProcessModuleLoadException(this, exc);
        }
    }

ModuleSettingsBase is available everywhere so TreeTabID, TreeModuleID, PersonTabID and PersonModuleID will be too. That’s what I wanted and it uses less code so thanks Olivier!

It would be nice to ditch the try catch but there’s no guarantee the value will be in the drop down list otherwise it would be even smaller. Still better though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:15:16+00:00Added an answer on May 28, 2026 at 12:15 am

    Create a wrapper class for your settings.

    public class TabModuleSettingsWrapper {
    
       private SettingsCollection _settings; // I do not know of which type your settings are.
    
       public TabModuleSettingsWrapper(SettingsCollection settings) {
           _settings = settings;
       }
    
       public int? TreeModuleID { 
            get { 
                string s = (string)_settings["TreeModuleID"];
                int id;
                return Int32.TryParse(s, out id) ? id : (int?)null;
            }
       }
    
       // Repeat this for all the settings
    }
    

    Now you can access the settings with:

    var settings = new TabModuleSettingsWrapper(TabModuleSettings);
    if (settings.TreeTabID.HasValue &&  settings.TreeModuleID.HasValue) {
        Do_SomethingWithTheIDs(settings.TreeTabID, settings.TreeModuleID);
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider this code block public void ManageInstalledComponentsUpdate() { IUpdateView view = new UpdaterForm(); BackgroundWorker
So I run this Windows Server 2008 security update and this code block is
Considering this code, can I be absolutely sure that the finally block always executes,
I have this block of code: users = Array.new users << User.find(:all, :conditions =>
I seem to be using this block of code alot in Python. if Y
If I have a block of code like this: def show @post = Post.find(params[:id])
In other words, a block of code like this: (setq initial-major-mode (lambda () (text-mode)
Any way I can get this working? I have a block of code: <p><a
This was working..and I moved the disposal code to the finally block, and now
I prefer to use long identifiers to keep my code semantically clear, but in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.