User Control in VB.Net

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.
1/7/2010 8:06:06 AM
Gravatar
Total Posts 22

User Control in VB.Net

I've followed Steve Land's steps to create a MojoPortal module in C# and, as I don't know C# very well, wanted to try to do the same in VB which I am more familiar with.  I managed to get it all to compile but I can't view a page once I have added the feature to it.  I get this error: 'VBTestProject.UI.VBUserControlModule' is not allowed here because it does not extend class 'System.Web.UI.UserControl' at the point where MojoPortal is trying to load the control.  I am inheriting System.Web.UI.UserControl in my class (I originally tried inheriting SiteModuleControl) the code for the class is below:

Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Configuration
Imports System.Globalization
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports mojoPortal.Web
Imports mojoPortal.Web.Framework
Imports mojoPortal.Web.UI
Imports log4net
Imports Resources

Namespace VBTestProject.UI

Partial Public Class VBUserControlModule
Inherits System.Web.UI.UserControl
' FeatureGuid d2d61fef-0503-4ac9-aeff-9e1ff55e6fb1

#Region "OnInit"

Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)
End Sub
#End Region

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

LoadSettings()
PopulateLabels()
PopulateControls()

End Sub

End Class
End Namespace

I'm sure it's something very basic that I've done wrong but I just can't figure it out.  I'd be very grateful for any help/advice.  At the moment I'm thinking it might be better to try to learn C# and go down that route.

Thanks

 

 

1/8/2010 6:48:58 AM
Gravatar
Total Posts 18439

Re: User Control in VB.Net

You compiled your code behind into a dll, does that dll exist in the Web/bin folder?

Make sure your post build event copies the dll up to Web/bin

You also have a .ascx file as part of your usercontrol right?

For best results you should set a reference to the mojoPortal.Web.UI project using a project reference. Then in your custom module you should inherit from SiteModuleControl instead of UserControl, though it can work with a plain UserControl.

Hope it helps,

Joe

1/8/2010 12:38:42 PM
Gravatar
Total Posts 22

Re: User Control in VB.Net

Hi Joe

Thanks for responding and sorry if this seems a bit dumb.

Yes, the dll is in the Web/bin folder and the ascx is there too (in a subfolder under Web).  I'm now inheriting from SiteModuleControl and have a project reference to mojoportal.web - I think that's what you mean when you say MojoPortal.Web.UI or am I looking in the wrong place.  I have based my solution on your mojoportal_mssql_only.sln so have included the same projects.  I have compared my C# and VB versions of the projects and just can't see what I'm missing. 

Thanks again.

Suzy

1/11/2010 1:56:49 PM
Gravatar
Total Posts 22

Re: User Control in VB.Net

I think I have resolved this so I'm posting it in case anyone else needs the info.  Apparently there is a bug in VS2008 and you have to reference the control in the designer code behind file as well.  So I put a reference to mojoPortal.Web.SiteModuleControl in the designer code behind and it is now working.  I expect there'll be a few more gotchas along the way but at least that one's solved.


 

1/11/2010 2:26:07 PM
Gravatar
Total Posts 18439

Re: User Control in VB.Net

Glad to hear you figured out the issue.

Best,

Joe

1/12/2010 5:50:58 AM
Gravatar
Total Posts 18439

Re: User Control in VB.Net

Hey Suzy,

Many thanks for the beers!

Cheers,

Joe

4/11/2010 1:53:53 PM
Gravatar
Total Posts 2

Re: User Control in VB.Net

I've run into the same problem and I am trying to add a reference to "mojoPortal.Web.SiteModuleControl", but it does not show up in my references so that I can add it. Am I missing something?

4/13/2010 7:01:16 AM
Gravatar
Total Posts 18439

Re: User Control in VB.Net

Right click the References node in your custom project and choose "Add Reference", click the Projects tab and select mojoPortal.Web

Hope it helps,

Joe

9/25/2010 7:50:31 AM
Gravatar
Total Posts 7

Re: User Control in VB.Net

Suzy can you post the final example.  I've tried everything to get my VB code to work and just can't.  I've all references, the page compiles fine but I can't get it to display.

ascx page:

<%@ Control Language="VB" AutoEventWireup="false" ClassName="AddAthlete.ascx" CodeBehind="AddAthlete.ascx.vb" Inherits="CoachAlert.UI.AddAthlete,mojoPortal.Web.SiteModuleControl" %>

<%@ Import Namespace="mojoPortal.Business" %>
<%@ Import Namespace="mojoPortal.Business.WebHelpers" %>
<%@ Import Namespace="mojoPortal.Web.Framework" %>
<%@ Import Namespace="mojoPortal.Web.Controls" %>
<%@ Import Namespace="mojoPortal.Web.Editor" %>
<%@ Import Namespace="mojoPortal.Net" %>

<portal:mojoPanel ID="mp1" runat="server" ArtisteerCssClass="art-Post" RenderArtisteerBlockContentDivs="true">
<mp:CornerRounderTop id="ctop1" runat="server" />
<asp:Panel ID="pnlWrapper" runat="server" CssClass="art-Post-inner panelwrapper linksmodule">
<portal:ModuleTitleControl id="Title1" runat="server" />
<portal:mojoPanel ID="MojoPanel1" runat="server" ArtisteerCssClass="art-PostContent">
<asp:Panel ID="pnlCoachAlert" runat="server" EnableViewState="false" CssClass="modulecontent">

Your custom form goes here.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />

</asp:Panel>
<div class="modulefooter"></div>
</portal:mojoPanel>
<div class="cleared"></div>
</asp:Panel>
<mp:CornerRounderBottom id="cbottom1" runat="server" />
</portal:mojoPanel>

 

CodeBehind:

 

Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Configuration
Imports System.Globalization
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports mojoPortal.Web
Imports mojoPortal.Web.Framework
Imports mojoPortal.Web.UI
'Imports log4net
Imports Resources
Imports CoachAlert.UI
'Namespace CoachAlert.UI
Partial Public Class AddAthlete
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Button1.Text = "Howdy"
    End Sub

End Class
'End Namespace

9/25/2010 8:17:00 AM
Gravatar
Total Posts 18439

Re: User Control in VB.Net

If you are using Codebehind then you have to compile it which produces a dll and this must be copied up to the Web/bin folder. Typically you can do this in a post build event.

There is a VB.NET example in our Hello World samples that uses inline code instead of codebehind, therefore it doesn't require pre-compiling and does not produce or need a dll in the bin folder.

Hope it helps,

Joe

9/25/2010 10:20:14 AM
Gravatar
Total Posts 7

Re: User Control in VB.Net

Thanks Joe for the quick response.

I have everything being copied, i.e. all my dlls etc. through post build events and they are all the web folder

xcopy /s /y "$(ProjectDir)bin\CoachAlert.UI.dll" "$(SolutionDir)Web\bin\"
xcopy /s /y "$(ProjectDir)bin\CoachAlert.Business.dll" "$(SolutionDir)Web\bin\"
xcopy /s /y "$(ProjectDir)bin\CoachAlert.Data.dll" "$(SolutionDir)Web\bin\"
xcopy /s /y "$(ProjectDir)AddAthlete\*.ashx" "$(SolutionDir)Web\AddAthlete\"
xcopy /s /y "$(ProjectDir)AddAthlete\*.ascx" "$(SolutionDir)Web\AddAthlete\"
xcopy /s /y "$(ProjectDir)AddAthlete\*.aspx" "$(SolutionDir)Web\AddAthlete\"
xcopy /s /y "$(ProjectDir)App_GlobalResources\*.resx" "$(SolutionDir)Web\App_GlobalResources\"
xcopy /s /y "$(ProjectDir)Setup\*" "$(SolutionDir)Web\Setup"

I even tried the code inline example and that didn't work either.

not sure what to try now.  maybe my setup on my web admin side in mojo portal is wrong, added it in admin and the created a new page where i added my 'feature'

My control source is:  AddAthlete/AddAthlete.ascx

I have a folder in the web folder called addathlete and have the ascx there.  

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