ascx in 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.
3/3/2008 4:54:43 AM
Gravatar
Total Posts 20

ascx in mojoportal

Hi,

I have there an aspx-page, which I created with VS2008 and C# as Code behind.

This page shall be included into Mojoportal as ascx (after searching by google,I guess changing from aspx to ascx is not that difficult, only changing the p into c and removing all html and forms tags)

But how do i get this ascx-file then into Mojoportal that I can create  a new page in the administration menu which will open the ascx when clicking on it?

thanks

Andi

3/3/2008 1:55:39 PM
Gravatar
Total Posts 18439

Re: ascx in mojoportal

Hi Andi,

A .ascx file is what is known as a UserControl, it can't be laoded directly, it can be used inside a page. Its generally used to encapuslate some functionality that you want to use on more than one page.

If you are trying to add a page you created to the admin menu you can do it by using the file Web/Setup/initialcontent/supplementaladminlinks/00001myadminlinks.config

What you should do is copy this file and use a new name so it doesn't get overwritten if you update mojoportal. Name it whateveryoulikewithnospaces.config

You'll see a commented out example in the file, you just need to uncomment it and edit it:

<!--
<adminMenuLink
resourceFile="MyResource"
resourceKey="test google link"
url="http://www.google.com"

/>

<adminMenuLink
resourceFile="MyResource"
resourceKey="test extra link2"
url="~/Admin/SiteSettings.aspx"

/>
-->

To uncomment it, remove the <!-- and -->

Use ~/ to represent the root of the site.

You can put more links in the file using the same syntax.

Hope it helps,

Joe

3/3/2008 2:11:17 PM
Gravatar
Total Posts 20

Re: ascx in mojoportal

oh, sorry, I think I wrote it a little bit ambigous.

I don't want to add things to the admin menu, I want to create a new page via the admin menu in mojoportal which will then use my ascx file as module. But I don't know how I can do this. If I copy my project folder into the web directory of mojoportal and create a new module where I use my ascx file as control source (http://localhost/mojoportal/Admin/ModuleDefinitions.aspx?defid=-1), and then create a new page using that module (http://localhost/mojoportal/Admin/PageSettings.aspx?start=1) I get strange compiler error messages when clicking at the new site (like namespace is not defined, or inherit can't be found/open - but all those errors can't be, because the ascx file was checked in Visual Studio debugger before).

So I wonder - what do I do wrong?

3/3/2008 2:24:50 PM
Gravatar
Total Posts 18439

Re: ascx in mojoportal

To make a UserControl that you can put on a page, you must inherit from SiteModuleControl (which itself inherits from UserControl)

If you have Visual Studio, you should open the mojoportal-complete.sln solution and study the SampleExternalModule project as it is a basic hello world example of creating something that plugs into the content system and can be put on a page. It uses post build events to copy the files under the Web project.

You then have to tell mojoportal about your custom feature. Look in Administration > Feature Modules to see where to enter the information to install your feature, ie the path to your .ascx and a name for your feature.

Then create a page using the icon to create a page then after saving the page, click the edit content link and your feature will show up in the dropdown list.

Hope it helps,

Joe

3/4/2008 4:33:23 AM
Gravatar
Total Posts 20

Re: ascx in mojoportal

Hi Joe,

thanks for the advice with the SampleExternalModule.

But I have still some comprehension questions:

You said it must inherit from "SiteModulControl", but in the SampleExternalModule project it inherits from "SampleExternalModule.SampleModuleControl". What is the difference and in which references do I find those things so that my ascx-file can inherit from it?

The post build events just copy the files into the correct folders in the mojoportal directory? Or is that still everything in the mp source code directory?

Sorry for all these questions, but it's all so new and confusing for me.

Andi

3/4/2008 4:54:18 AM
Gravatar
Total Posts 18439

Re: ascx in mojoportal

There are several levels of inheritance going on. The SampleExternalModule.ascx file inherits from SampleExternalModule.SampleModuleControl class which lives in its code behind file SampleExternalModule.ascx.cs. But if you look at the code in this file you see it inherits from SiteModuleControl

public partial class SampleModuleControl : SiteModuleControl

the only difference with a normal User Control created by VS, it would be

public partial class SampleModuleControl : UserControl

SiteModuleControl inherits from UserControl and adds things needed to plug in to mojoportal.

Yes, the post build copies file to the correct location under the web project. The main thing is it copies its compiled dll (and any dlls it depends on) into the bin folder. You can have it put your .ascx file wherever you like. Notice how WebStore has all its files in a WebStore folder (both within its own project and when it copies to Web/WebStore. Thats a good way to keep your custom code organized and separate from the core of mojoportal.

So wherever your post build event puts the .ascx file, you set the correct path when you install it under Administration > Feature Modules

Notice that the Sample External Module is not installed in the site by default but you can install it by going into Administration > Feature Modules - Add New. For the control path enter

Modules/SampleExternalModule.ascx

and name it Sample or whatever you like. Now it will appear in the feature list and you can add instances of it to pages. Of course its not very useful but you can see how it plugs in.

Hope it helps,

Joe

 

3/4/2008 5:07:21 AM
Gravatar
Total Posts 20

Re: ascx in mojoportal

it works! Now my module works! Yipeehh! :-)

Thank you so much for your great help, Joe!

 

Andi

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