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).

8/24/2006 10:00:57 AM
Gravatar
Total Posts 18439

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

I think it would be clearer to you if you were working with the mojoportal source code instead of just against the compiled version. Then you could look at how other modules are implemented.

Pages that are in the menu can contain any modules but modules should never link to these pages for the reason you have found, they have no knowledge of the menu or page ids.

But modules can have related .aspx pages that they link to. These pages should inherit from mojoBasePage to support skinning but these pages do not appear in the menu and are only available by links from within the module because the module does know about these pages.

For example Blog Module, the module is BlogModule.ascx but it links also to BlogEdit.aspx and BlogView.aspx but neither of these pages are available in the menu they can only be accessed by links from the BlogModule.ascx. BlogModule passes in parameters to these pages and knows about these pages but it does not know about pages in the menu. In fact the blog module can exist in more than one menu page because you can have as many blogs in a site as you want but each has a different module id and item ids for the posts.

Why not just work with the mojoPortal source code where you can see the examples. There are even examples of external module in the source code which shows how you can have a post build action in the external project to copy the output (dll, .ascx, .aspx) from your external module to the correct locations in mojoportal web


Hope it helps,

Joe
8/26/2006 1:38:03 AM
Gravatar
Total Posts 9

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

Hi,

I downloaded the latest version of mojoPortal. I see there is base class named mojoBasePage so any own page can inherited from it.

However I must develop extra features for mojoPortal which use framework 1.1 so there is no mojoBasePage class.

What I need to do?
I created page e.g. MyPage.aspx with following code:

<%@ Page language="c#" Codebehind="MyPage.aspx.cs" AutoEventWireup="false" Inherits="Test.MyPage" %>
<%@ Register TagPrefix="portal" Namespace="mojoPortal.Web" Assembly="mojoPortal.Web" %>
<portal:MasterPage id="MPContainer" runat="server">
<portal:ContentRegion id="MPTitle" runat="server"></portal:ContentRegion>
<portal:ContentRegion id="MPLeftPane" runat="server"></portal:ContentRegion>
<portal:ContentRegion id="MPContent" runat="server"></portal:ContentRegion>
<portal:ContentRegion id="MPRightPane" runat="server"></portal:ContentRegion>
<portal:ContentRegion id="MPPageEdit" runat="server"></portal:ContentRegion>
</portal:MasterPage>
Then I added this page using administrator features Add/Edit page and I checked "Use url" with http://myserver/MyPage.aspx

Now I want to add same existing or my own modules (content) to this page by administrator features. I don't see any solution to do this with no mojoPasePage parent class. Yes I know that it can be done by inserting code to MyPage.aspx.cs to load extra modules (the same as in default.aspx.cs code file) but it is not good way.

Thank you.
Best regards
wtct
8/26/2006 5:38:40 AM
Gravatar
Total Posts 18439

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

Hi,

You would use the 1-0-4-src download not the latest version for 1.1 framework development

Yes there is no mojoBasePage in that version and it uses Paul Wilson's MasterPages implementation
Content modules can only be added using the web interface to virtual pages which are served from Default.aspx?pageid=somenumber (though friendly urls can be mapped over these)
New physical Pages that you add cannot be used this way though you can make them appear in the menu as you have found

If you want to add modules using the web interface you should just use virtual pages
I usually only add physical pages for edit pages or module specific pages and I link to those from inside the module not from the menu

Hope it helps,

Joe
8/28/2006 2:44:50 AM
Gravatar
Total Posts 9

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

Hi,

Your last post was ok but I have two new problems.

Problem 1.

When I use map url then query parameters in url do not work. What I mean? I created two pages (using admin panel) named PageOne.aspx and PageTwo.aspx. Then I added user control as a content (new module) to these pages: one named ModuleOne.ascx and ModuleTwo.ascx. 
I maped one adress http://server/PageTwo.aspx (firiendly url) to http://server/default.aspx?pageindex=...&pageid=..
Inside ModuleOne.ascx I have a link with http://server/PageTwo.aspx?myParam=... 
In page_load event ModuleTwo.ascx (content of PageTwo.aspx) I want to recive myParam value.
How can I do it?

Problem 2.

I have button on Default.aspx. Code of this Button is:
Response.Redirect("SomeExistingPage.aspx").
When open the browser with http://server/ and click on button I get error message that page could not be displayed. But when I open browser and go to http://server/default.aspx (it is the same page as http://server/) and next click on button then correct page is displayed (SomeExistingPage.aspx)

Thank you.

wtct

8/28/2006 3:02:43 AM
Gravatar
Total Posts 18439

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

I'm afraid I don't have solution to problem 1 at the moment. The idea of the friendly urls was that you wouldn't see the query string params. If you need additional query string params you may not be able to use friendly urls on that page.
I will look into this and see if I can figure out a solution for a future release.

Problem 2 you could try using more fully qulified urls or something like

Response.Redirect(Page.ResolveUrl("~/SomeExistingPage.aspx"));

Keep in mind that if you deploy on mono it will be case sensitive
You must sign in to post in the forums. This thread is closed to new posts.