4

I am developing a DNN module and I want to display an info message at the top of my ContentPane, not above the actual module. I have found that DotNetNuke.UI.Skins.Skin.AddPageMessage() should just do the thing. I am not getting the behavior I want though, the message just won't display at all.

There are few overloads of this method, one group accepting a Page object, the other one taking a Skin object.

public static void AddPageMessage(Page page, string heading, string message, ModuleMessage.ModuleMessageType moduleMessageType)

public static void AddPageMessage(Skin skin, string heading, string message, ModuleMessage.ModuleMessageType moduleMessageType)

I did take a look into the DNN source and found out that in the end they're actually using the same private static AddPageMessage(...) method, which just looks for a ContentPane within the provided control and adds a new ModuleMessage to the collection of its controls.

What should I pass as a Page or Skin parameter to get this correclty working?

Thanks ...

Matus Nemcik
  • 240
  • 2
  • 13

2 Answers2

4

The private AddPageMessage method takes a fairly ambiguous "Control" as the first parameter. I believe that needs to be the current Skin, as it does a FindControl for ContentPane.

Doing something like this should get you a reference to the current skin:

var skin = Skin.GetSkin((PageBase)this.Page);
Skin.AddPageMessage(skin, "Header", "Message", ModuleMessageType.GreenSuccess);
Ian Robinson
  • 16,892
  • 8
  • 47
  • 61
  • thanks for your reply, I have tried the way you describe before, but unfortunately it does not seem to work. I've tried it both with default and custom skins. While debugging dnn source, the FindControl in fact found the ContentPane, but its Controls collection was empty (shouldn't be, since there should be at least my module) and after adding a new ModuleMessage object to the collection nothing happened and no message was shown on the page. Any idea? – Matus Nemcik Mar 12 '12 at 08:18
  • Hmm, I'm seeing the same thing. Weird. I'm not entirely sure why that's happening at the moment. – Ian Robinson Mar 13 '12 at 18:18
  • Some more evidence...the method IS working for adding the "DNN Pro Trial" message. But when I call it myself it isn't showing up in the UI, even though it finds the ContentPane... – Ian Robinson Mar 13 '12 at 18:28
1

the reason why the messages are not showing up is that you turned on "enable partial rendering" in the controlssetting of the modulecontrols.

If you are using AJAX (this is happening if you set the partial rendering to true) the DNN modulemessages are turned off from DNN itselfe.

Its enough if you have turned the partial rendering on just 1 control (dont have to be your control where you are acting from) on your page. DNN will wrap the whole page into ajax script manager and messages are not working anymore.

*EDIT 26.04.2012 10:45:

You can get the current ScriptManager by executing the following Code for example in you Page_Load(). If the manager is null, you dont have ajax enabled and the modulemessages should work. If bIsAjaxEnabled is true the modulemessages are disabled.

ScriptManager manager = AJAX.GetScriptManager(Page);
if (manager != null)
{
   bool bIsAjaxEnabled = manager.SupportsPartialRendering;
}
noonecares
  • 216
  • 1
  • 6
  • How can I be sure that the page is wrapped by ajax script manager? I have only a simple page with one module on it, no module control has partial rendering enabled, seems like there is no ajax script manager (checked page source) but page messages still aren't displayed. Any clue? – Matus Nemcik Apr 25 '12 at 18:22
  • I've been playing around with it but still with no success :( After checking for SupportsPartialRendering, it is indeed true ... What I also did is that I looked into the DNN source and found out that the ScriptManager is being added to every Page (as a method call in DotNetNuke.Framework.PageBase.OnInit() method, where the ScriptManager is added to every page). Have I overlooked something? – Matus Nemcik Apr 26 '12 at 18:07
  • Yes, the scriptmanager is being added to every page. But if you enable "SupportPartialRendering" DNN (Version 6) will replace the ScriptManager with the telerik ajaxScriptmanager. From there on AJAX is enabled and this means that modulemessages are not working anymore. Just try to make a total empty control on a new created page. place a Button to the module which shows up a modulemessage if you click. Normally it should work. – noonecares Apr 27 '12 at 06:51
  • Well, I performed a clean install of new instance of DNN, created a simple module (by using http://christoctemplate.codeplex.com/ template) which in View.ascx checks for scriptmanager at Page_Load and tries to display a page message in testButton_OnClick. The script manager I get from the AJAX.GetScriptManager() is not null and is of type Telerik.Web.UI.RadScriptManager. SupportsPartialRendering is true. All controls (View, Edit, Settings) have partial rendering turned off. Any idea? – Matus Nemcik Apr 27 '12 at 07:15
  • Hmm for the first look your moduletemplates are looking pretty clean and nice. I couldnt find any problem for the first shot. All my experiences are from DNN5 handling with modulemessages concerning ajax. If they changed something big in DNN6 then maybe the problem could be something else. I will have a closer look at this issue at the weekend and let you know if I could find something. which Version of DNN are you using? – noonecares Apr 27 '12 at 07:44
  • Yes, it is really strange ... I am using the latest 06.01.05 version. Thanks for your help ... – Matus Nemcik Apr 27 '12 at 08:32