How to add new an .ascx module to mojoportal

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.
8/23/2006 7:47:34 AM
Gravatar
Total Posts 9

How to add new an .ascx module to mojoportal

Hello,

I need help with adding user control (.ascx) to mojoPortal. I created control by using Visual Studio

2003. This cotrol do nothing special.

The header of this control is:

<%@ Control Language="c#" AutoEventWireup="false" Codebehind="SimpleModule.ascx.cs"

Inherits="Test.SimpleModule" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>

I uploaded this files (SimpleModule.ascx.cs and SimpleModule.ascx) to server. I added this control

to mojoPortal by using admin->Feature Modules->Add new module type. When I used it at main page I

recived page with following error:
"Specified cast is not valid"

[InvalidCastException: Specified cast is not valid.]
   mojoPortal.Web.SiteHome.Page_Load(Object sender, EventArgs e) +1338
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750

Could someone explain me what I am doing wrong. I would be very appreciate for help.
I want just to add new module to mojoportal.

8/23/2006 8:52:53 AM
Gravatar
Total Posts 18439

Re: How to add new an .ascx module to mojoportal

Hi,

The main thing is in the Code file SimpleModule.ascx.cs you need to inherit from

mojoPortal.Web.SiteModuleControl

instead of

UserControl

like this:

public class SimpleModule: mojoPortal.Web.SiteModuleControl
{

...

}

You can look at one of the simple built in modules for example ContactForm.ascx.cs

Hope that helps,

Joe
8/23/2006 9:56:02 AM
Gravatar
Total Posts 9

Re: How to add new an .ascx module to mojoportal

Hi!

Yes it helps. Now there is no page with error "Specified cast is not valid". Thank you very much for fast reply. Now, almost everything is ok except this:

Every elements in user control are displayed but code of SimpleModule.ascx.cs file is not executed after I added mojoPortal.Web.SiteModuleContro. I don't know why..

wtct

8/23/2006 10:01:13 AM
Gravatar
Total Posts 18439

Re: How to add new an .ascx module to mojoportal

Did you just add your control directly into the mojoportal web project and compile it into the same dll as mojoPortal.Web.dll or is your code in a spearate project compiled into its own dll?

Maybe you could paste the code and I'll take a look. When you paste it into the forum use the "Paste as Text" toolbar (the one with a clipboard and notepad, in the top toolbar of the forum post editor.

You are using mojoportal 1.0.4 source code in VS 2003 right?

Joe
8/23/2006 10:08:13 AM
Gravatar
Total Posts 9

Re: How to add new an .ascx module to mojoportal

Hi!

I use separate project to create user control. I added all necessery references (asemblies) from mojoPortal to my project. So I don't use source code from mojoPortal, I just develop additional features.

wtct

8/23/2006 10:37:40 AM
Gravatar
Total Posts 18439

Re: How to add new an .ascx module to mojoportal

ok, then make sure and compile your code and drop the dll into the bin folder of mojoportal


Hope it helps,

Joe
8/23/2006 10:51:45 AM
Gravatar
Total Posts 9

Re: How to add new an .ascx module to mojoportal

Hi,

I have still the same problem, I rebuilded everything. I included code of ascx and ascx.cs

To save your time, I prepared simple example which render hello world. It doesn't work (Page_Load is not executed) even on my local computer after I add mojoPortal.Web.SiteModuleControl besides System.Web.UI.UserControl

Here is the code:

<%@ Control Language="c#" AutoEventWireup="false" Codebehind="SimpleModule.ascx.cs" Inherits="Test.SimpleModule" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:Label id="Label1" runat="server">Label</asp:Label>

namespace Test
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for SimpleModule.
/// </summary>
public class SimpleModule : mojoPortal.Web.SiteModuleControl
{
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
Label1.Text = "Hello world";
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

8/23/2006 11:01:07 AM
Gravatar
Total Posts 9

Re: How to add new an .ascx module to mojoportal

Hi,

I noticed that my SimpleModule class executes overriden method called OnInit. This method is also in System.Web.UI.UserControl parent class so it works. But it doesn't works when I inherite from mojoPortal.Web.SiteModuleControl (maybe there is no virtual method called OnInit)?

What do you think?

wtct.

8/23/2006 11:05:41 AM
Gravatar
Total Posts 18439

Re: How to add new an .ascx module to mojoportal

yes that might be the problem try removing that and instead add a constructor and hook up your initilaization code like this:

public SimpleModule ()
{
    this.Init += new System.EventHandler(Page_Init);
}

private void Page_Init(object sender, EventArgs e)
{

    base.OnInit(e);
    InitializeComponent();

}


private void InitializeComponent()
{
    this.Load += new System.EventHandler(this.Page_Load);
   
}

Hope it helps,

Joe
8/23/2006 11:20:29 AM
Gravatar
Total Posts 9

Re: How to add new an .ascx module to mojoportal

Hi,

Now it works fine... :) but I had to removed base.OnInit(e) - it coused "Reference not set..."

Thank for time spent on it.

Best regards

wtct

8/24/2006 9:37:46 AM
Gravatar
Total Posts 9

Re: How to add new an .ascx module to mojoportal

Hi,

Now I need help with understanding some logic of creating new page and user controls.

I'm working with mojoPortal a couple of days. I have following problem.

I want to add my own page to mojoPortal.
I uploaded it on server and now I need to add some existing (my own or from mojoPortal) modules  to this page. I want to do it using admistrator features - is it possible?

 

When I add new page by using administrator features then page is not created phisical, but I need realy aspx file in order to link to this page from my sample module. Howerver, in this way I can add any module to created page in that way. I know that I can get link form newly added page (the link is with attribute pageIndex and pageID) but when somebody delete and create one more time this page then I have to change link in my sample module (I have to correct pageID).

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