OneLazy
OneLazy

Reputation: 509

How to Show And UnShow DNN module

I just got off to this problem in my module development where I needed to ask this to some expert. My question is, what could be the (best) way of showing and unshowing module in DNN7 depending on the value of custom field I provided in profile properties. I need something like:

if(customfield == "somevalue")
{
    module1.show;
}

how can this be achieved?

thanks,

Upvotes: 1

Views: 101

Answers (1)

Fix It Scotty
Fix It Scotty

Reputation: 2852

The easiest thing you can do is wrap a panel around your module view's html content.

<asp:Panel ID="pnlModuleContainer" runat="server">

...

</asp:Panel>

Then in your module view's codebehind, do something like this:

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        pnlModuleContainer.Visible = false;
        if (User.Profile.GetPropertyValue("CustomFieldName") == "somevalue")
        {
            pnlModuleContainer.Visible = true;
        }
        else
        {
            DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "You need 'somevalue' to see this module",
                        DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.BlueInfo);
        }
    }
    catch (Exception exc) //Module failed to load
    {
        Exceptions.ProcessModuleLoadException(this, exc);
    }
}

Upvotes: 2

Related Questions