Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 9th, 2007, 06:22 PM
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem Converting C# to VB.NET in ASP.NET

I'm still a newbie to this whole process, so please bear with me. I'm including all of the referenced code at the bottom of this post.

I'm trying to work with example code (Listing 7.10) from an online version of the book "XML for ASP.NET - Chapter 7: XSLT and ASP.NET", which can be seen at http://www.topxml.com/dotnet/articles/xslt/default.asp.

But when I converted the C# code to VB.NET using the following converter site: http://www.developerfusion.co.uk/uti...sharptovb.aspx, and I ran the ASP.NET page from within Visual Web Developer 2k5 Express, I received this error message:

Compiler Error Message: BC30260: 'btnSubmit' is already declared as 'Protected Dim WithEvents btnSubmit As System.Web.UI.WebControls.Button' in this class.

Source Error:

Line 17: Public Class XsltGolfer
Line 18: Inherits System.Web.UI.Page
Line 19: Protected btnSubmit As System.Web.UI.WebControls.Button
Line 20: Protected pnlSelectGolfer As System.Web.UI.WebControls.Panel
Line 21: Protected pnlTransformation As System.Web.UI.WebControls.Panel

I've tried to research the error message, but I can't find a solution. So if anyone can let me know what I'm doing wrong, that would be great. Thanks for any help.

ASP.NET code - xsltGolfer.aspx
<%@ Page Language="VB" CodeFile="xsltGolfer.aspx.vb" Inherits="TestBed.Chapter7.XsltGolfer" Debug="True" %>
        <style type="text/css">
            .blackText {font-family:arial;color:#000000;} .largeYellowText 
            {font-family:arial;font-size:18pt;color:#ffff00;} .largeBlackText 
            {font-family:arial;font-size:14pt;color:#000000;} .borders {border-left:1px 
            solid #000000;border-right:1px solid #000000; border-top:1px solid 
            #000000;border-bottom:1px solid #000000;}
        <form method="post" runat="server">
            <asp:Panel ID="pnlSelectGolfer" Runat="server">
                <TABLE width=400 bgColor=#efefef border=0 class="borders">
                        <TD bgColor=#02027a>
                            <SPAN style="FONT-SIZE: 14pt; COLOR: #ffffff; FONT-FAMILY: arial">
                                Select a Golfer by Name:
                            <asp:DropDownList id=ddGolferName runat="server">
                            <asp:Button id=btnSubmit runat="server" Text="Get Golfer!">
            <asp:Panel ID="pnlTransformation" Runat="server" Visible="False">
                <DIV id=divTransformation runat="server">
                    <asp:LinkButton id=lnkBack Runat="server" Text="Back"> Back</asp:LinkButton></P>
C# version - xsltGolfer.aspx.cs
namespace TestBed.Chapter7
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Xml;
    using System.Xml.XPath;
    using System.Xml.Xsl;
    using System.IO;
    using System.Text;

    /// <summary>
    ///        Summary description for test.
    /// </summary>
    public class XsltGolfer : System.Web.UI.Page    
        protected System.Web.UI.WebControls.Button btnSubmit;
        protected System.Web.UI.WebControls.Panel pnlSelectGolfer;
        protected System.Web.UI.WebControls.Panel pnlTransformation;
        protected System.Web.UI.WebControls.DropDownList ddGolferName;
        protected System.Web.UI.WebControls.LinkButton lnkBack;
        protected System.Web.UI.HtmlControls.HtmlGenericControl divTransformation;
        private string xmlPath;

        public XsltGolfer() 
            Page.Init += new System.EventHandler(Page_Init);

        protected void Page_Init(object sender, EventArgs e) 
            xmlPath = Server.MapPath("listing7.1.xml");

        #region Web Form Designer generated code
        /// <summary>
        ///    Required method for Designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
            this.lnkBack.Click += new System.EventHandler(this.lnkBack_Click);
            this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
            this.Load += new System.EventHandler(this.Page_Load);


        protected void btnSubmit_Click(object sender, System.EventArgs e) {

            string xslPath = Server.MapPath("xsltGolfer.xsl"); 
            XmlTextReader xmlReader = null;
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            try {
                xmlReader = new XmlTextReader(xmlPath);

                //Instantiate the XPathDocument Class
                XPathDocument doc = new XPathDocument(xmlReader);

                //Instantiate the XslTransform Classes
                XslTransform transform = new XslTransform();
                //Add Parameters
                XsltArgumentList args = new XsltArgumentList();
                //Call Transform() method
                transform.Transform(doc, args, sw);
                //Hide Panels
                this.pnlSelectGolfer.Visible = false;
                this.pnlTransformation.Visible = true;
                this.divTransformation.InnerHtml = sb.ToString();
            catch (Exception excp) {
            finally {

private void Page_Load(object sender, System.EventArgs e) {
    if (!Page.IsPostBack) {

        protected void lnkBack_Click(object sender, System.EventArgs e)
            this.pnlSelectGolfer.Visible = true;
            this.pnlTransformation.Visible = false;
private void FillDropDown(string element) 
    string name = "";
    System.Xml.XmlTextReader reader = new XmlTextReader(xmlPath);
    object firstNameObj = reader.NameTable.Add("firstName");
    while (reader.Read()) 
        if (reader.Name.Equals(firstNameObj)) 
            name = reader.ReadString();
            ListItem item = new ListItem(name,name);
VB.NET verison - xsltGolfer.aspx.vb
Imports System.Text
Imports System.IO
Imports System.Xml.Xsl
Imports System.Xml.XPath
Imports System.Xml
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI
Imports System.Web.SessionState
Imports System.Web
Imports System.Drawing
Imports System.Data
Imports System.ComponentModel
Imports System.Collections
Imports System
Namespace TestBed.Chapter7
    Public Class XsltGolfer
        Inherits System.Web.UI.Page
        Protected btnSubmit As System.Web.UI.WebControls.Button
        Protected pnlSelectGolfer As System.Web.UI.WebControls.Panel
        Protected pnlTransformation As System.Web.UI.WebControls.Panel
        Protected ddGolferName As System.Web.UI.WebControls.DropDownList
        Protected lnkBack As System.Web.UI.WebControls.LinkButton
        Protected divTransformation As System.Web.UI.HtmlControls.HtmlGenericControl
        Private xmlPath As String

        Public Sub New()
            AddHandler Page.Init, AddressOf Page_Init
        End Sub

        Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
            xmlPath = Server.MapPath("listing7.1.xml")
        End Sub

        Private Sub InitializeComponent()
            AddHandler Me.lnkBack.Click, AddressOf Me.lnkBack_Click
            AddHandler Me.btnSubmit.Click, AddressOf Me.btnSubmit_Click
            AddHandler Me.Load, AddressOf Me.Page_Load
        End Sub

        Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim xslPath As String = Server.MapPath("xsltGolfer.xsl")
            Dim xmlReader As XmlTextReader = Nothing
            Dim sb As StringBuilder = New StringBuilder
            Dim sw As StringWriter = New StringWriter(sb)
                xmlReader = New XmlTextReader(xmlPath)
                Dim doc As XPathDocument = New XPathDocument(xmlReader)
                Dim transform As XslTransform = New XslTransform
                Dim args As XsltArgumentList = New XsltArgumentList
                args.AddParam("golferName", "", Me.ddGolferName.SelectedItem.Value)
                transform.Transform(doc, args, sw)
                Me.pnlSelectGolfer.Visible = False
                Me.pnlTransformation.Visible = True
                Me.divTransformation.InnerHtml = sb.ToString
            Catch excp As Exception
            End Try
        End Sub

        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            If Not Page.IsPostBack Then
            End If
        End Sub

        Protected Sub lnkBack_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Me.pnlSelectGolfer.Visible = True
            Me.pnlTransformation.Visible = False
        End Sub

        Private Sub FillDropDown(ByVal element As String)
            Dim name As String = ""
            Dim reader As System.Xml.XmlTextReader = New XmlTextReader(xmlPath)
            Dim firstNameObj As Object = reader.NameTable.Add("firstName")
            While reader.Read
                If reader.Name.Equals(firstNameObj) Then
                    name = reader.ReadString
                    Dim item As ListItem = New ListItem(name, name)
                End If
            End While
        End Sub
    End Class
End Namespace
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
help, converting vb.net few lines to C# nesrine C# 3 March 6th, 2007 10:43 AM
Converting C# to VB.net ninel General .NET 0 August 11th, 2006 12:36 PM
Problem with Exercise in Beg. asp.net for VB.net! mrfella71 BOOK: Beginning ASP.NET 1.0 1 October 23rd, 2005 12:06 PM
converting code from c# to VB.net drachx General .NET 0 October 20th, 2004 11:19 PM
converting DTS package from VB 6 to VB .NET petroleo Pro VB Databases 0 August 18th, 2003 05:01 PM

All times are GMT -4. The time now is 02:48 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.