473,809 Members | 2,876 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting ASP.NET Page from VB to C#

Hi All,

I'm trying to convert some ASP.NET code that I found at
http://weblogs.asp.net/dannychen/arc...02/432190.aspx from VB
to C#.

I've managed to convert the portion that is in the <script></script>
section of the file fine (I think) but I've been unable to convert the
code in each of the <asp:Label /tags so far. Can anyone point me in
the right direction?

The only thing that the code is supposed to do is allow for a custom
CSS tags to be added to the sitemap file for the site so that each menu
item can have its own CSS. The original code along with the section
that I have converted is shown below.

Thanks,
Kris
Original Code
===========
<%@ Master Language="VB" CodeFile="Maste rPage.master.vb "
Inherits="Maste rPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">

<script runat="server">
REM http://weblogs.asp.net/dannychen/arc...02/432190.aspx
Shared styles As New System.Collecti ons.Generic.Dic tionary(Of
String, String)
Protected Sub Menu1_MenuItemD ataBound(ByVal sender As Object, _
ByVal e As
System.Web.UI.W ebControls.Menu EventArgs)
styles(e.Item.V aluePath) = CType(e.Item.Da taItem,
SiteMapNode)("s tyle")
End Sub</script>

<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Menu ID="Menu1" runat="server"
DataSourceID="S iteMapDataSourc e1" Orientation="Ho rizontal"
StaticDisplayLe vels="2"
OnMenuItemDataB ound="Menu1_Men uItemDataBound" >
<StaticItemTemp late>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath ") ) %>' />
</StaticItemTempl ate>
<DynamicItemTem plate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath ") ) %>' />
</DynamicItemTemp late>
</asp:Menu>
<asp:SiteMapDat aSource ID="SiteMapData Source1" runat="server"
/>
<div>
<asp:ContentPla ceHolder ID="ContentPlac eHolder1"
runat="server">
</asp:ContentPlac eHolder>
</div>
</form>
</body>
</html>

Converted Section
==============
<script runat="server">
public static System.Collecti ons.Generic.Dic tionary<string, string>
styles = new System.Collecti ons.Generic.Dic tionary<string, string>();

protected void Menu1_MenuItemD ataBound(object sender, MenuEventArgs
e)
{
styles[e.Item.ValuePat h] =
((SiteMapNode)e .Item.DataItem)["style"];
}
</script>

Sep 26 '06 #1
5 2322
q
You don't have to change anything in the ASP.NET controls.
eval("valuepath ") may look like VB, but it's ASP.NET.

k.************* @gmail.com wrote:
Hi All,

I'm trying to convert some ASP.NET code that I found at
http://weblogs.asp.net/dannychen/arc...02/432190.aspx from VB
to C#.

I've managed to convert the portion that is in the <script></script>
section of the file fine (I think) but I've been unable to convert the
code in each of the <asp:Label /tags so far. Can anyone point me in
the right direction?

The only thing that the code is supposed to do is allow for a custom
CSS tags to be added to the sitemap file for the site so that each menu
item can have its own CSS. The original code along with the section
that I have converted is shown below.

Thanks,
Kris
Original Code
===========
<%@ Master Language="VB" CodeFile="Maste rPage.master.vb "
Inherits="Maste rPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">

<script runat="server">
REM http://weblogs.asp.net/dannychen/arc...02/432190.aspx
Shared styles As New System.Collecti ons.Generic.Dic tionary(Of
String, String)
Protected Sub Menu1_MenuItemD ataBound(ByVal sender As Object, _
ByVal e As
System.Web.UI.W ebControls.Menu EventArgs)
styles(e.Item.V aluePath) = CType(e.Item.Da taItem,
SiteMapNode)("s tyle")
End Sub</script>

<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Menu ID="Menu1" runat="server"
DataSourceID="S iteMapDataSourc e1" Orientation="Ho rizontal"
StaticDisplayLe vels="2"
OnMenuItemDataB ound="Menu1_Men uItemDataBound" >
<StaticItemTemp late>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath ") ) %>' />
</StaticItemTempl ate>
<DynamicItemTem plate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath ") ) %>' />
</DynamicItemTemp late>
</asp:Menu>
<asp:SiteMapDat aSource ID="SiteMapData Source1" runat="server"
/>
<div>
<asp:ContentPla ceHolder ID="ContentPlac eHolder1"
runat="server">
</asp:ContentPlac eHolder>
</div>
</form>
</body>
</html>

Converted Section
==============
<script runat="server">
public static System.Collecti ons.Generic.Dic tionary<string, string>
styles = new System.Collecti ons.Generic.Dic tionary<string, string>();

protected void Menu1_MenuItemD ataBound(object sender, MenuEventArgs
e)
{
styles[e.Item.ValuePat h] =
((SiteMapNode)e .Item.DataItem)["style"];
}
</script>
Sep 26 '06 #2
Thank you for the response q. When I do the following:

<DynamicItemTem plate>
<asp:Label runat="server" ID="Label1" Text='<%# Eval("Text") %>'
Style='<%# styles( Eval("valuepath ") ) %>' />
</DynamicItemTemp late>

I receive the following error:

Error 3 'ASP.masterpage _master.styles' is a 'field' but is used like a
'method' D:\Visual Studio\CustomMe nuItems.CS\Mast erPage.master 24

I've included the entire source for the new page (the one that genrates
the error) below along with the contents of my sitemap file in case it
helps. Thanks again.

MasterPage.mast er
===============
<%@ Master Language="C#" AutoEventWireup ="true"
CodeFile="Maste rPage.master.cs " Inherits="Maste rPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">

<script runat="server">
public static System.Collecti ons.Generic.Dic tionary<string, string>
styles = new System.Collecti ons.Generic.Dic tionary<string, string>();

protected void Menu1_MenuItemD ataBound(object sender, MenuEventArgs
e)
{
styles[e.Item.ValuePat h] =
((SiteMapNode)e .Item.DataItem)["style"];
}
</script>
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div id="Head">
<asp:Menu ID="Menu1" runat="server"
DataSourceID="S iteMapDataSourc e1"
OnMenuItemDataB ound="Menu1_Men uItemDataBound" Orientation="Ho rizontal"
StaticDisplayLe vels="2">
<DynamicItemTem plate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( Eval("valuepath ") ) %>' />
</DynamicItemTemp late>
<StaticItemTemp late>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( Eval("valuepath ") ) %>' />
</StaticItemTempl ate>
</asp:Menu>
<asp:SiteMapDat aSource ID="SiteMapData Source1"
runat="server" />
</div>
<div>
<asp:ContentPla ceHolder ID="ContentPlac eHolder1"
runat="server">
</asp:ContentPlac eHolder>
</div>
</form>
</body>
</html>

Web.sitemap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microso ft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.as px" title="Home" description="Ma in
page">
<siteMapNode url="Page1.aspx " title="Page1" description="Pa ge1
Description" style="backgrou nd-color:Blue; color:White;">
<siteMapNode url="Page1.1.as px" title="Page1.1"
description="Pa ge1 Description" style="backgrou nd-color:Yellow;
color:Black;" />
</siteMapNode>
<siteMapNode url="Page2.aspx " title="Page2" description="Pa ge2
Description" style="backgrou nd-color:Black; color:Yellow;" />
</siteMapNode>
</siteMap>

q wrote:
You don't have to change anything in the ASP.NET controls.
eval("valuepath ") may look like VB, but it's ASP.NET.

k.************* @gmail.com wrote:
Hi All,

I'm trying to convert some ASP.NET code that I found at
http://weblogs.asp.net/dannychen/arc...02/432190.aspx from VB
to C#.

I've managed to convert the portion that is in the <script></script>
section of the file fine (I think) but I've been unable to convert the
code in each of the <asp:Label /tags so far. Can anyone point me in
the right direction?

The only thing that the code is supposed to do is allow for a custom
CSS tags to be added to the sitemap file for the site so that each menu
item can have its own CSS. The original code along with the section
that I have converted is shown below.

Thanks,
Kris
Original Code
===========
<%@ Master Language="VB" CodeFile="Maste rPage.master.vb "
Inherits="Maste rPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">

<script runat="server">
REM http://weblogs.asp.net/dannychen/arc...02/432190.aspx
Shared styles As New System.Collecti ons.Generic.Dic tionary(Of
String, String)
Protected Sub Menu1_MenuItemD ataBound(ByVal sender As Object, _
ByVal e As
System.Web.UI.W ebControls.Menu EventArgs)
styles(e.Item.V aluePath) = CType(e.Item.Da taItem,
SiteMapNode)("s tyle")
End Sub</script>

<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Menu ID="Menu1" runat="server"
DataSourceID="S iteMapDataSourc e1" Orientation="Ho rizontal"
StaticDisplayLe vels="2"
OnMenuItemDataB ound="Menu1_Men uItemDataBound" >
<StaticItemTemp late>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath ") ) %>' />
</StaticItemTempl ate>
<DynamicItemTem plate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles( eval("valuepath ") ) %>' />
</DynamicItemTemp late>
</asp:Menu>
<asp:SiteMapDat aSource ID="SiteMapData Source1" runat="server"
/>
<div>
<asp:ContentPla ceHolder ID="ContentPlac eHolder1"
runat="server">
</asp:ContentPlac eHolder>
</div>
</form>
</body>
</html>

Converted Section
==============
<script runat="server">
public static System.Collecti ons.Generic.Dic tionary<string, string>
styles = new System.Collecti ons.Generic.Dic tionary<string, string>();

protected void Menu1_MenuItemD ataBound(object sender, MenuEventArgs
e)
{
styles[e.Item.ValuePat h] =
((SiteMapNode)e .Item.DataItem)["style"];
}
</script>
Sep 26 '06 #3
Does anyone else out there have any ideas? Thanks.

Sincerely,
Kris

Sep 27 '06 #4
There's several VB --C# free online converters.

http://www.eggheadcafe.com/articles/...converter.aspx

http://www.developerfusion.co.uk/uti...sharptovb.aspx

http://www.carlosag.net/Tools/CodeTr...r/default.aspx

http://www.dotnettaxi.com/Tools/Converter.aspx

SharpDevelop ( the free C# IDE for .Net ) also has a code translator:
http://www.icsharpcode.net/OpenSource/SD/Download/

Stick your code into them ( just the code, not the HTML )
and see which one does the best job for you.

When you're done, please tell us which one worked best, OK ?


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
<k.************ *@gmail.comwrot e in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
Does anyone else out there have any ideas? Thanks.

Sincerely,
Kris

Sep 27 '06 #5
Great links Juan - I've been looking for some good converters! The only
one I've used so far is the demo of Instant C#: VB to C# Converter from
Tangible Software (http://www.tangiblesoftwaresolutions.com) but I
don't have enough experience with it yet to give it a positive or
negative review.

I managed to get the code working this morning without using a
converter. Here's the final code. The only major change from what I
posted above is in the <asp:Labelporti on. I had to change the
late-binding code for the Style attribute to the following:

<asp:Label runat="server" ID="Label1" Text='<%# Eval("Text") %>'
Style='<%# styles[(string)Eval("V aluePath")] %>' />
<%@ Master Language="C#" AutoEventWireup ="true"
CodeFile="Maste rPage.master.cs " Inherits="Maste rPage"
Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<script runat="server">
// Original source (VB.NET)
//
http://www.dotnetslackers.com/Micros...enu_Items.aspx

// Articles on adding custom icons to menu using sitemap
//
http://www.gotdotnet.com/Community/U...6-4df7cad7b028

public static System.Collecti ons.Generic.Dic tionary<string, string>
styles = new System.Collecti ons.Generic.Dic tionary<string, string>();

protected void Menu1_MenuItemD ataBound(object sender, MenuEventArgs
e)
{
styles[e.Item.ValuePat h] =
((SiteMapNode)e .Item.DataItem)["style"];
}
</script>
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div id="Head">
<asp:Menu ID="Menu1" runat="server"
Orientation="Ho rizontal" StaticDisplayLe vels="2"
DataSourceID="S iteMapDataSourc e1"
OnMenuItemDataB ound="Menu1_Men uItemDataBound" >
<StaticItemTemp late>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles[(string)Eval("V aluePath")] %>' />
</StaticItemTempl ate>
<DynamicItemTem plate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("Text") %>' Style='<%# styles[(string)Eval("V aluePath")] %>' />
</DynamicItemTemp late>
</asp:Menu>
<asp:SiteMapDat aSource ID="SiteMapData Source1"
runat="server" />
</div>
<div>
<asp:ContentPla ceHolder ID="ContentPlac eHolder1"
runat="server">
</asp:ContentPlac eHolder>
</div>
</form>
</body>
</html>
Juan T. Llibre wrote:
There's several VB --C# free online converters.

http://www.eggheadcafe.com/articles/...converter.aspx

http://www.developerfusion.co.uk/uti...sharptovb.aspx

http://www.carlosag.net/Tools/CodeTr...r/default.aspx

http://www.dotnettaxi.com/Tools/Converter.aspx

SharpDevelop ( the free C# IDE for .Net ) also has a code translator:
http://www.icsharpcode.net/OpenSource/SD/Download/

Stick your code into them ( just the code, not the HTML )
and see which one does the best job for you.

When you're done, please tell us which one worked best, OK ?


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
<k.************ *@gmail.comwrot e in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
Does anyone else out there have any ideas? Thanks.

Sincerely,
Kris
Sep 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1915
by: Dan Stromberg | last post by:
I've written up a page about how to convert native binary data to another platform's native binary data, as I did some fortran data conversions for a client. The programs and documentation are at: http://dcs.nac.uci.edu/~strombrg/converting-binary.html So far, the page includes a variety of programs written in C or python to do:
20
7363
by: Al Moritz | last post by:
Hi all, I was always told that the conversion of Word files to HTML as done by Word itself sucks - you get a lot of unnecessary code that can influence the design on web browsers other than Internet Explorer. Our computer expert in my company had told me already a while ago that I should learn HTML and encode myself. I was never inclined to do so (I am no computer expert), and when upon his suggestion I looked how my pages (converted to...
3
2991
by: lostinspace | last post by:
Hello, My sites were created primarily with tables as layout. :-( I have two page designs which I used frequently and hopefully somebody can provide some insight as to whether its best to remain with tables in CSS or use an alternative. The first page: http://www.mi-harness.com/hof/0a0.html Is part of a frames section, with 17 such pages A-Z. It is my desire to have
2
1271
by: Dave | last post by:
Hi, Im considering converting a legacy application from asp to aspx (vb) - just for the purpose of learning (Im new at .net, but experienced at vbscript) What I need to get my head around, is page security. Currently this app has a database login which sets session values for username etc Pages within this web are then protected by the usual "If session("loggedin") = true then..." kind of code.
2
2290
by: Ben Amada | last post by:
Hello, A partner is going to be creating some HTML files that I plan on converting to user controls (UC) and dynamically load at runtime. I'm guessing Visual Studio doesn't come with some utililty to convert HTML files to UCs? IOW, I'll have to manually convert each HTML file to a UC? I've never used user controls before, so I'm wondering what I need to add and remove to each UC (or HTML file) to make this work. For instance, I...
1
1301
by: Friso Wiskerke | last post by:
Hi All, We've got an VS.2003 ASPNET (VB) webproject which we would like to convert to VS.2005 so that we can make use of the Master Page feature. Converting the initial pages to 2005 is not such a problem (some minor errors) but we run into trouble when we're trying to insert a converted page into a master page content-placeholder. The original page has some Javascript in it which ofcourse references to controls in a form in the page....
3
2131
by: varuna | last post by:
Hi, I have doubt on converting html page to .net i mean if i designed a page in frontpage or in a Dreamweaver so that page i mean instead of designing a web page in .net using toolbox i need to convert this html page as a .net web page. How to do that shal i open the html file in a .net or shal i copy the file into that folder, im confusing with that so please let me know and explain me briefly. Thanks in advance Varuna
7
2502
by: Coleen | last post by:
Does anyone have any good detailed information on the conversion process? We are in the process of converting 2 projects from 2003 to 2005 and have some conversion errors that I can not find answers to. First, we have a lot of UserControls. I am getting the error "Type uc_mc_btn_footer is not defined." where uc_mc_btn_footer is the name of the UserControl. Also, on almost all of our UserControls the conversion has remmed out all my code...
25
4398
by: Blasting Cap | last post by:
I keep getting errors that pop up when I am trying to convert an application from dotnet framework 1.1 to framework 2.0. The old project was saved in sourcesafe from Visual Studio 2003, and I have opened it in Visual Studio 2005. I've cleared up most errors, but have one that beats the heck out of me. I have a page: sales/Item.aspx that has several datagrids in it.
1
2647
by: =?Utf-8?B?SG93YXJkIFBpbnNsZXk=?= | last post by:
I'm trying to convert a Web Site to the Web Application project model and I'm running into compile errors that do not seem to be covered by the guidance I found at "Converting a Web Site Project to a Web Application Project". The issue is that standard ASP.NET controls that are embedded as child controls within the ContentTemplate of the Ajax Control Toolkit's TabContainer/TabPanel are no longer visible to the page (and result in compile...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10633
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10375
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.