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 ExtensionsModulesModulesUser Security within ModulesUser Security within Modules
New Post
1/14/2016 11:01 PM

Hi All,

I am developing my own module and have done a few now but I have come across a situation where I want to show and hide data in the module, say a checkbox depending on the Security Group.

I have been using the following in the skin:

                        <%  If DotNetNuke.Security.PortalSecurity.IsInRole("Chasmont Staff")  Then %>

                        <% End If %>

Which works fine for skin files but causes exceptions in the module.

Is there some comparable code I can use in a module to do this?  I have done a lot of searching but have not been able to solve it.

Any help would be gratefully appreciated!

Thanks Mike

New Post
1/15/2016 10:08 AM
in your modules, you should evaluate visibility in code behind (depending on the model you are using)

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
New Post
1/15/2016 11:34 AM
Sebastian is right, you can handle the entire thing with code behind...

But if you still want to work with classic ASP in your module view .ascx file then you need to add a public property to the module's view code behind which will allow you to access it from the module's view.ascx in the same manner as you are doing with your skin's page.ascx.

New Post
1/15/2016 12:06 PM
I think the OP already plans to do this in the code behind file.

He wants to know what the equivalent code should look like. Can you help him?

Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
New Post
1/15/2016 3:43 PM
Simple classic ASP with a code behind public property might look like this...

Somewhere in the Module Code Behind: view.ascx.cs

private bool _ShowPager = false; // typically you will set this value in your modules Page_Load event based on a module setting
public bool ShowPager
get { return _ShowPager; }
set { _ShowPager = value; }

Somewhere in the Module view.ascx Code:

<%if (ShowPager) {%>


One all code behind alternative would be to place a asp literal control on the module's view.ascx and populate it's Text property with markup by a function called from the Page_Load event whereby there would be no classic with the brackets on your view.ascx. You would however be then forced to build the UI HTML code via server side logic which can also get a little bit ugly. Really it's a case by case scenario in my book and if something is working and not a security or performance problem, that is probably the most important.

With a literal somewhere on the modules view.ascx such as:

When using a literal the modules view.ascx.cs Page_Load would look something like:

protected void Page_Load(object sender, EventArgs e)
if(DotNetNuke.Security.PortalSecurity.IsInRole("Chasmont Staff") ){
ltlMyCode.Text = "
"; // You can apply all your necessary if logic here to drive your dynamic UI or abstract it into a separate function if it's DRYer

Both achieve the same result and with Razor you could provide another version doing yet again... the same thing. A little HTML got stripped by the forum editor but it's close..
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesUser Security within ModulesUser Security within Modules

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