Getting ModuleGuid in a UserControl

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
6/2/2009 6:04:58 PM
Gravatar
Total Posts 245
mojoPortal Community Expert

Getting ModuleGuid in a UserControl

I'm building a module and need to use my ModuleGuid on a User Control ascx page.  The control is used inside a Grid.

I have no problem getting my ModuleGuid on aspx pages using...

Module module = new Module(ModuleId);
_gModule = module.ModuleGuid;

However on my User controls ModuleID is -1 because I can't pass parms to my User Control and get it using ModuleId = WebUtils.ParseInt32FromQueryString("mid", -1);

I get my site user Guid fine:

SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
if (siteUser != null) _gUser = siteUser.UserGuid;

and get SiteGuid fine:

_gSite = siteSettings.SiteGuid;

My User control is of type SiteModuleControl

I searched through dozens of User Controls in mojoPortal but none of them use ModuleGuid.

Any idea's
 

 

 

6/2/2009 6:10:26 PM
Gravatar
Total Posts 245
mojoPortal Community Expert

Re: Getting ModuleGuid in a UserControl

I thought about using a session variable and I will if there is no other solution.

I just hate using session variables.

6/3/2009 12:54:28 AM
Gravatar
Total Posts 550

Re: Getting ModuleGuid in a UserControl

Hi

I think you have it in this.ModuleGuid if your user control inherit from the  SiteModuleControl.

I hope helps you

Asad

 

6/3/2009 10:54:47 AM
Gravatar
Total Posts 245
mojoPortal Community Expert

Re: Getting ModuleGuid in a UserControl

Thanks for the reply Asad.

In my LoadSetting() of my User Control the value of
this.ModuleGuid is {00000000-0000-0000-0000-000000000000} which I believe is Guid.Empty.

I'm thinking maybe I need to somehow get the value using parent.page or something???

Thanks again for your suggestion.

6/3/2009 11:13:34 AM
Gravatar
Total Posts 18439

Re: Getting ModuleGuid in a UserControl

When I put this in the LoadSettings method of a module (I tried it on Html and Feed Manager) 

Guid test = this.ModuleGuid;

If I set a breakpoint on that line and step through the code its never an empty guid

Are you calling LoadSettings from Page_Load or OnInit?

How is it (and why) are you loading module controls from inside a grid?

Does your UserControl inheit from SiteModule like this:

public partial class FeedManagerModule : SiteModuleControl

Hope it helps,

Joe

6/3/2009 11:27:26 AM
Gravatar
Total Posts 550

Re: Getting ModuleGuid in a UserControl

Hi

I don't know why you add a module in a Grid.I think some events of a module that included in a Grid maybe not occur. SiteModuleControl had beeb designed to add on a page and probably not work in a Grid, you maybe in a wrong path.

Hope helps

Asad

6/3/2009 11:52:39 AM
Gravatar
Total Posts 245
mojoPortal Community Expert

Re: Getting ModuleGuid in a UserControl

Hi

Here's the class declaration for my module:

public partial class LinksControl : SiteModuleControl

I call my LoadSetting() method from Page_Load

The user control is being used as an edit/insert for rows in the Grid.  The User Control has  database driven dropdown lists which are populated in the code behind.  The arguments for all dropdowns use SiteGuid and ModuleGuid but ModuleGuid is not available.

The application is a working one created outside of mojoPortal.

When I ported it over to mojoPortal I added SiteGuid and ModuleGuid to all tables in the application giving me a triple Prime Key which is fine.  I need the ModuleGuid because there could be more than one instance of the Module in the Site.

6/3/2009 12:01:36 PM
Gravatar
Total Posts 18439

Re: Getting ModuleGuid in a UserControl

As Asad said, SiteModuleControl was not designed for this kind of use. Its meant only for use as the base class for a UserControl that is the entry point to a feature that plugs into the content management system as a content feature. I would never use one inside a grid myself.

In Default.aspx.cs where we load modules into a page we pass in the module configuration to the control like this:

Control c = Page.LoadControl("~/" + module.ControlSource);
if (c == null) { continue; }

if (c is SiteModuleControl)
{
SiteModuleControl siteModule = (SiteModuleControl)c;
siteModule.SiteId = siteSettings.SiteId;
siteModule.ModuleConfiguration = module;
}

parent.Controls.Add(c);

Wherever your data for populating the grid is coming from, I would just include the siteguid, moduleid and moduleguid in the resultset of the data. I'm not sure I understand why you are trying to use a SiteModule there, but its not an expected use.

Hope it helps,

Joe

6/3/2009 12:07:38 PM
Gravatar
Total Posts 550

Re: Getting ModuleGuid in a UserControl

Hi

Ok. Now you add a Grid control and other databound controls to this empty module and develop code behind to populate data sources of these from your database.

Hope helps

Asad.

6/3/2009 2:19:04 PM
Gravatar
Total Posts 245
mojoPortal Community Expert

Re: Getting ModuleGuid in a UserControl

Thanks you both.

The supplied code above gives me my solution.

In the next build is it possible you could add a set code for ModuleGuid?

In SiteModuleControl.cs at line 118

Add the set below to ModuleGuid

public Guid ModuleGuid
{
    get { return moduleConfiguration == null ? Guid.Empty : moduleConfiguration.ModuleGuid; }
    set
       {
          if (moduleConfiguration == null) moduleConfiguration = new Module(value);
          moduleConfiguration.ModuleGuid = value;
       }
}

This help me out and keep me out of the core mojoPortal code.  Hopefully it will not affect anything else.  It works on my code copy.
Why do I use so many User Controls?  Just something I started years ago and it's become a habit.

The beer is on the way...

Rick Hubka

 

 

6/3/2009 2:32:17 PM
Gravatar
Total Posts 18439

Re: Getting ModuleGuid in a UserControl

Hi Rick,

I don't have any problem with adding that setter as it is similar to the one for moduleid, I will add it, but I think the implementation of your own feature is problematic and I would advise against it. The problem is you are databinding a grid and in the itemdatabound event of each row you are making another call to the db by using this constructor on module which is not a good idea at all and won't scale well. 

Its fine to use UserControls but SiteModule is a special UserControl designed for a much different purpose than what you are doing. 

Best,

Joe 

You must sign in to post in the forums. This thread is closed to new posts.