Use the dnn module as the container of usercontrol

Source: Internet
Author: User

Dnn modules generally cannot be used as an independent system, but module development requires low coupling between modules, such as HTML modules, but slightly more complex modules, for example, in a news system (24-Year-Old yongsun news system), many modules are set up to implement various functions, but in fact there is only one folder yongri-newsarticles in topmodules, this is because a news system that is independently completed requires high cohesion. Although several modules are defined, due to cohesion, it can only be regarded as one module in programming.

Therefore, I figured out a way to create a container usercontrol in the module entry usercontrol, that is, to load the usercontrol of other usercontrol in this module, the specific module to be loaded is set on the setting page.

Key code of seting. ascx:

# Region base method implementations
Public override void loadsettings ()
{
Try
{
If (! Page. ispostback)
{
Bindcategories ();

If (! Null. isnull (tabmodulesettings ["controlkey"])
{
String controlkey = (string) tabmodulesettings ["controlkey"];
Listitem = ddlcontrolkey. Items. findbyvalue (controlkey );
If (listitem! = NULL)
{
Listitem. Selected = true;
}
}

Key code of container usercontrol

String controlkey;

Private void page_init ()
{
Injectcontrol ();
}

Protected void page_load (Object sender, eventargs E)
{

}

Protected void injectcontrol ()
{
If (! Null. isnull (settings ["controlkey"])
{
Controlkey = (string) settings ["controlkey"];
}

If (! String. isnullorempty (this. controlkey ))
{
String strcontrolpath = This. resolveurl ("~ /Topics topmodules/crossarticle/"+ controlkey );
// Control CTL = This. loadcontrol (strcontrolpath );
// This. Controls. Add (CTL );

Portalmodulebase = (portalmodulebase) This. loadcontrol (strcontrolpath );

If (portalmodulebase! = NULL)
{
Portalmodulebase. moduleconfiguration = base. moduleconfiguration;

// Set the Control ID to the resource file name (ie. controlname. ascx = controlname)
// This is necessary for the localization in pagebase
Portalmodulebase. ID = path. getfilenamewithoutextension (strcontrolpath );

This. Controls. Add (Control) portalmodulebase );
(Control) portalmodulebase). databind ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.