Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesModule Settings From Custom ControlModule Settings From Custom Control
Previous
 
Next
New Post
1/27/2010 10:50 AM
 

Setup:
1. Module view control has a placeholder object.
2. Custom control is added to place holder at runtime.

Is there a better way to get module settings from the custom control than the following?
CType(Parent.Parent, Entities.Modules.PortalModuleBase).Settings("SETTING_NAME")

Thanks,

Brad

 
New Post
1/27/2010 12:21 PM
 

Have the custom control inherit from "PortalModuleBase", then pass the "ModuleConfiguration" from the loading control into the control that is loaded.

MyControl controlInstance = new MyControl();
controlInstance.ModuleConfiguration = this.ModuleConfiguration;
//Now add it to the placeholder.

 


-Mitchel Sellers
Microsoft MVP, ASPInsider, DNN MVP
CEO/Director of Development - IowaComputerGurus Inc.
LinkedIn Profile

Visit mitchelsellers.com for my mostly DNN Blog and support forum.

Visit IowaComputerGurus.com for free DNN Modules, DNN Performance Tips, DNN Consulting Quotes, and DNN Technical Support Services
 
New Post
1/27/2010 4:21 PM
 

 Thanks Mitch, that worked. However, it didn't work when I overloaded the LoadControl Function to allow me to pass objects to my user controls.

I ended up setting it in my overloaded LoadControl function.

Here is the code below.

Private Overloads Function LoadControl(ByVal UserControlPath As StringByVal ParamArray constructorParameters As Object()) As PortalModuleBase
  Dim constParamTypes As New Generic.List(Of Type)
  For Each constParam As Object In constructorParameters
    constParamTypes.Add(constParam.[GetType]())
  Next

  Dim ctl As PortalModuleBase = TryCast(Page.LoadControl(UserControlPath), PortalModuleBase)
  ctl.ModuleConfiguration = Me.ModuleConfiguration

  ' Find the relevant constructor
  Dim constructor As System.Reflection.ConstructorInfo = ctl.[GetType]().BaseType.GetConstructor(constParamTypes.ToArray())

  'And then call the relevant constructor
  If constructor Is Nothing Then
    Throw New MemberAccessException("The requested constructor was not found on : " + ctl.[GetType]().BaseType.ToString())
  Else
    constructor.Invoke(ctl, constructorParameters)
  End If

  Return
 ctl ' Finally return the fully initialized Control

End Function 

 

 
New Post
1/27/2010 5:19 PM
 

Instead of having the child control inherit from PortalModuleBase, could you change the constructor of the child control so it also accepts Settings as one of the parameters and pass it using reflection as you are already doing with the other parameters?

Nik

 


Nik Kalyani
Co-founder
DotNetNuke Corporation
Blog | Twitter | FaceBook
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesModule Settings From Custom ControlModule Settings From Custom Control


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out