apsx / portal mode page converted to portal

Craig Wyatt asked on June 4, 2015 19:09

I am going to try my best to explain what I am doing.

I am working on a new site in kentico's portal mode and have a control from another site that was built in the aspx/portal mode so the old page has a template file with a code behind file.

I am trying to bring that page over to the new site but I am not sure how to get the code from the templates code behind file into the new template that is built in portal mode.

I do have a custom web part on the page that I added the vb code to but it is not working.

Any help would be greatly appreciated.

Recent Answers


lawrence whittemore answered on June 4, 2015 19:11

I meant to post this as me.

0 votesVote for this answer Mark as a Correct answer

Brad Vrudney answered on June 4, 2015 19:22

What errors are you receiving lawrence?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 4, 2015 19:28

I'd suggest determining what needs to be in code and what doesn't. The majority of aspx or custom templates or code I've come across can be handled with macros, custom event handlers and such. If you need to create a custom web part that would be best, then move it into a template from there.

0 votesVote for this answer Mark as a Correct answer

lawrence whittemore answered on June 4, 2015 19:35

this is the page, http://66.231.199.97:8004/plan-your-trip.aspx it's a server 500 error GetWaypointCount is a webmethod that lives in the code file for the template.

0 votesVote for this answer Mark as a Correct answer

lawrence whittemore answered on June 4, 2015 19:42

I think the issue may be with the server not access the webmethod... if that's even a thing.

0 votesVote for this answer Mark as a Correct answer

lawrence whittemore answered on June 4, 2015 19:44

POST http://66.231.199.97:8004/Plan-Your-Trip.aspx/GetWaypointCount 500 (Internal Server Error)

0 votesVote for this answer Mark as a Correct answer

Brad Vrudney answered on June 4, 2015 21:25

Here is the error you are receiving: Cannot use 'vbscript' because another language has been specified earlier in this page (or was implied from a CodeFile attribute)

I thought you misspoke earlier when you said "vb". Kentico is in c# and does not support vb development. As brenden suggested, maybe you could move this code into kentico configuration, instead of using the code.

0 votesVote for this answer Mark as a Correct answer

lawrence whittemore answered on June 4, 2015 21:41

that was me trying other things... I really don't know what I am doing. Our main developer is out of the office and I was trying to tackle this.

I'm not sure what you mean that kentico doesn't support vb. Our developers write everything here in vb. the code behind files they create are always .vb at the end...

The problem that I am having is that I built the site in portal modal and the code I am trying to copy to the site was originally built on an aspx page in the code behind file. I need to add it to my page template but I built my page template in the portal modal.

If it helps the code looks to be a bunch of webmethods. this is the code behind if that will help

    Imports CMS.UIControls
Imports System.Data
Imports System.Web.Services

Partial Class _chamber_default
                    Inherits TemplatePage

#Region "Web Methods"
                    <WebMethod>
                    Public Shared Function GetWaypointCount() As String
                                        If HttpContext.Current.Session("WaypointCount") = Nothing Then
                                                            Return ""
                                        Else
                                                            Return HttpContext.Current.Session("WaypointCount").ToString()
                                        End If
                    End Function

                    <WebMethod>
                    Public Shared Function AddTripWaypoint(MemberID As Integer) As Boolean
                                        'Add Member Id to Trip Planner Session Variable
                                        If HttpContext.Current.Session("WaypointCount") = Nothing Then
                                                            HttpContext.Current.Session("WaypointCount") = "1"
                                                            HttpContext.Current.Session("Waypoint1") = MemberID.ToString

                                                            Return True
                                        Else
                                                            Dim count As Integer = CInt(HttpContext.Current.Session("WaypointCount"))

                                                            'Increment the count by 1
                                                            count = count + 1

                                                            'Add another waypoint to the session
                                                            HttpContext.Current.Session("Waypoint" + count.ToString) = MemberID.ToString

                                                            'Update Waypoint count and update total
                                                            HttpContext.Current.Session("WaypointCount") = count.ToString

                                                            Return True
                                        End If

                                        Return False
                    End Function

                    <WebMethod>
                    Public Shared Function UpdateWaypointOrder(MemberList As String) As String
                                        HttpContext.Current.Session("WaypointMemberList") = MemberList.ToString

                                        Return MemberList.ToString
                    End Function
#End Region

End Class
0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on June 4, 2015 23:48

You can hack a website project to use both VB and C#, I have ran across it several times. It is bad practice and should never be done. If they mixed both VB and C# in the aspx template web site you are going to have a lot of issues and code needs to be converted if you are moving it to the portal engine only model. If this is the case, you have a big problem growing and future upgrades and such will not work. Nothing you do in Kentico should be written in VB.

Anyhow the code above will not run in full portal mode. I am not sure if you can even get it to run without hacking the web.config and a lot of other areas.

0 votesVote for this answer Mark as a Correct answer

Brad Vrudney answered on June 5, 2015 12:16

Thanks Charles, I had no idea! I've never come across someone doing that before. One solution, Lawrence, is to convert the code to c#:

http://www.developerfusion.com/tools/convert/vb-to-csharp/

There is more work that needs to be done to make it work, but if you do decide to go this route, this tool will give you a leg up.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 5, 2015 14:12 (last edited on June 5, 2015 14:20)

I agree with Charles 99%. The exception is if you don't know C#, you can easily use VB.net and C#.net together in the same solution or project without issue. It's not as big of a deal as Charles suggests it might be, but he does have a point. The problem comes in to play if you modify any of the base controls within Kentico. If you do and you use VB, the upgrade/hotfix will overwrite them and you'll be back to C#.

I move legacy VB controls into C# apps all the time, simply so I don't have convert or rewrite the code and test it. I know it worked in VB and if I convert it or change it to C#, there could be logic changes and extensive testing will have to be done, which adds time to a project.

A few points to take away Lawrence:

  • Kentico supports both VB & C#
  • Any NEW code should be written in the applications primary language
  • Moving legacy code (VB or C#) to a website developed in it's counterpart is fine, be sure you follow my second bullet point though.

See Microsoft documentation here about mixing multiple languages.

See additional reasons on StackOverflow.

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on June 5, 2015 15:39

Don't forget, that unfortunately, ASP.NET 5 and beyond will not support web forms per Microsoft. You can use .NET 4.6 but the future is pretty much sealed. Sooner than later this will affect Kentico. If you have multiple languages in a web site, the day is coming that you will have a lot of challenges.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 5, 2015 18:21

Great point Charles! Really though, I have a hard time believing Microsoft will drop Web Forms support for something that has been in use for 13+ years in this short of a time. It will probably be like Windows XP then, people will stay on .NET 4.6 or older until they no longer support .NET 4.6. So there's a few years left...

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on June 5, 2015 19:44 (last edited on June 6, 2015 04:48)

Hang on then, at my last internal meeting it was identified that Fall/Winter of 2016 is going to get quite bumpy. With the 4.6 Full Core and EOL, and system.web. Unless there is a dramatic change in their vision, and the internal roadmaps and outdates I have reviewed.

To be honest about the coming changes, I am not happy one bit about it. Having to rebuild everything for vNext is not cool at all.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.