VB to C sharp anyone can point out which is the equivalent

H

Hai Nguyen

I'm learning C sharp and do not like vb much. I'm creatiing a wepage using
panel to test myself. I tried to use these code below, which is written in
VB, and to transform them to c sharp but I got hard time to understand vb
syntax. I don't know if anyone in here can point out which is the equivalent
object used in c sharp.

Translate these two lines to C sharp:

Sub Next_Click(Sender As Object, e As EventArgs)
Select Case Sender.Parent.ID


Thanks



<%@ Page Language="vb" %>
<html>
<head>
<script runat="server">
Sub Page_Load()
If Not IsPostBack Then
Step1.Font.Bold = True
End If
End Sub
Sub Next_Click(Sender As Object, e As EventArgs)
Select Case Sender.Parent.ID
Case "Page1"
Page1.Visible = False
Step1.Font.Bold = False
Page2.Visible = True
Step2.Font.Bold = True
Case "Page2"
Page2.Visible = False
Step2.Font.Bold = False
Page3.Visible = True
Step3.Font.Bold = True
ReviewFName.Text &= FirstName.Text
ReviewMName.Text &= MiddleName.Text
ReviewLName.Text &= LastName.Text
ReviewEmail.Text &= Email.Text
ReviewAddress.Text &= Address.Text
ReviewCity.Text &= City.Text
ReviewState.Text &= State.Text
ReviewZip.Text &= Zip.Text
End Select
End Sub

Sub Previous_Click(Sender As Object, e As EventArgs)
Select Case Sender.Parent.ID
Case "Page2"
Page2.Visible = False
Step2.Font.Bold = False
Page1.Visible = True
Step1.Font.Bold = True
Case "Page3"
Page3.Visible = False
Step3.Font.Bold = False
Page2.Visible = True
Step2.Font.Bold = True
End Select
End Sub
</script>
<style type="text/css">
div
{
background:silver;
width:400px;
border:2px outset;
margin:5px;
padding:5px;
}
</style>
</head>
<body>
<form runat="server">
<asp:label id="RegWiz" text="Registration Wizard" font-bold="true"
font-size="16" font-name="verdana" runat="server"/>
<br/>
<asp:label id="Step1" text="Step 1: Enter Personal Info"
font-name="verdana" runat="server"/>
<br/>
<asp:label id="Step2" text="Step 2: Enter Address Info"
font-name="verdana" runat="server"/>
<br/>
<asp:label id="Step3" text="Step 3: Review" font-name="verdana"
runat="server"/>
<br/>
<asp:panel id="Page1" runat="server">
<table align="center">
<tr>
<td>
<asp:label id="FirstNameLabel" text="First Name:"
runat="server"/>
</td>
<td>
<asp:textbox id="FirstName" runat="server"/>
</td>
</tr>
<tr>
<td>
<asp:label id="MiddleNameLabel" text="Middle Name:"
runat="server"/>
</td>
<td>
<asp:textbox id="MiddleName" runat="server"/>
</td>
</tr>
<tr>
<td>
<asp:label id="LastNameLabel" text="Last Name:"
runat="server"/>
</td>
<td>
<asp:textbox id="LastName" runat="server"/>
</td>
</tr>
<tr>
<td>
<asp:label id="EmailLabel" text="Email:" runat="server"/>
</td>
<td>
<asp:textbox id="Email" runat="server"/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:button id="P1Previous" Text="Previous"
enabled="false" onclick="Previous_Click" runat="server"/>
<asp:button id="P1Next" Text="Next" onclick="Next_Click"
runat="server"/>
<input id="P1Reset" type="reset" runat="server"/>
</td>
</tr>
</table>
</asp:panel>
<asp:panel id="Page2" visible="false" runat="server">
<table align="center">
<tr>
<td>
<asp:label id="AddressLabel" text="Street Address:"
runat="server"/>
</td>
<td>
<asp:textbox id="Address" runat="server"/>
</td>
</tr>
<tr>
<td>
<asp:label id="CityLabel" text="City:" runat="server"/>
</td>
<td>
<asp:textbox id="City" runat="server"/>
</td>
</tr>
<tr>
<td>
<asp:label id="StateLabel" text="State:" runat="server"/>
</td>
<td>
<asp:textbox id="State" runat="server"/>
</td>
</tr>
<tr>
<td>
<asp:label id="ZipLabel" text="Zip Code:" runat="server"/>
</td>
<td>
<asp:textbox id="Zip" runat="server"/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:button id="P2Previous" Text="Previous"
onclick="Previous_Click" runat="server"/>
<asp:button id="P2Next" Text="Next" onclick="Next_Click"
runat="server"/>
<input id="P2Reset" type="reset" runat="server"/>
</td>
</tr>
</table>
</asp:panel>
<asp:panel id="Page3" visible="false" runat="server">
<table align="center">
<tr>
<td colspan="2">
<asp:label id="ReviewFName" text="First Name: "
runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:label id="ReviewMName" text="Middle Name: "
runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:label id="ReviewLName" text="Last Name: "
runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:label id="ReviewEmail" text="Email: "
runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:label id="ReviewAddress" text="Address: "
runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:label id="ReviewCity" text="City: " runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:label id="ReviewState" text="State: "
runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:label id="ReviewZip" text="Zip: " runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:button id="P3Previous" Text="Previous"
onclick="Previous_Click" runat="server"/>
<asp:button id="P3Next" Text="Next" enabled="false"
onclick="Next_Click" runat="server"/>
<input id="P3Reset" type="reset" disabled="true"
runat="server"/>
</td>
</td>
</tr>
</table>
</asp:panel>
</form>
</body>
</html>
 
K

Kevin Spencer

Translate these two lines to C sharp:
Sub Next_Click(Sender As Object, e As EventArgs)
Select Case Sender.Parent.ID

private void Next_Click(object Sender, EventArgs e)
{
switch (Sender.ParentID)
{
}
}

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
T

Tim Heuer

VB Lines;

Sub Next_Click(Sender As Object, e As EventArgs)
Select Case Sender.Parent.ID

C# translation with some additional:

void Next_Click(object sender, EventArgs e)
{
swith (Sender.Parent.ID)
{
case "youridstring" :
// do something
break;
default :
// provide a default behavior
break;
}
// other code in the function.
}
 
H

Hai Nguyen

It did not work, would you please tell me more. This is the error it throws
after I used you way: I don't know if i have to import anything

public void Next_Click(object sender, System.EventArgs e)

{

switch(sender.Parent.ID)

.....
}

the only object works I tried was this.Parent.ID but when I ran it it failed

please more insutructions
-------------------

code:

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;

namespace Energy

{

/// <summary>

/// Summary description for panel.

/// </summary>

public class panel : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Label RegWiz;

protected System.Web.UI.WebControls.Label Step1;

protected System.Web.UI.WebControls.Label Step2;

protected System.Web.UI.WebControls.Label Step3;

protected System.Web.UI.WebControls.Label FirstNameLabel;

protected System.Web.UI.WebControls.TextBox FirstName;

protected System.Web.UI.WebControls.Label MiddleNameLabel;

protected System.Web.UI.WebControls.TextBox MiddleName;

protected System.Web.UI.WebControls.Label LastNameLabel;

protected System.Web.UI.WebControls.TextBox LastName;

protected System.Web.UI.WebControls.Label EmailLabel;

protected System.Web.UI.WebControls.TextBox Email;

protected System.Web.UI.WebControls.Button P1Previous;

protected System.Web.UI.WebControls.Button P1Next;

protected System.Web.UI.WebControls.Panel Page1;

protected System.Web.UI.WebControls.Label AddressLabel;

protected System.Web.UI.WebControls.TextBox Address;

protected System.Web.UI.WebControls.Label CityLabel;

protected System.Web.UI.WebControls.TextBox City;

protected System.Web.UI.WebControls.Label StateLabel;

protected System.Web.UI.WebControls.TextBox State;

protected System.Web.UI.WebControls.Label ZipLabel;

protected System.Web.UI.WebControls.TextBox Zip;

protected System.Web.UI.WebControls.Button P2Previous;

protected System.Web.UI.WebControls.Button P2Next;

protected System.Web.UI.WebControls.Panel Page2;

protected System.Web.UI.WebControls.Label ReviewFName;

protected System.Web.UI.WebControls.Label ReviewMName;

protected System.Web.UI.WebControls.Label ReviewLName;

protected System.Web.UI.WebControls.Label ReviewEmail;

protected System.Web.UI.WebControls.Label ReviewAddress;

protected System.Web.UI.WebControls.Label ReviewCity;

protected System.Web.UI.WebControls.Label ReviewState;

protected System.Web.UI.WebControls.Label ReviewZip;

protected System.Web.UI.WebControls.Button P3Previous;

protected System.Web.UI.WebControls.Button P3Next;

protected System.Web.UI.WebControls.Panel Page3;

protected System.Web.UI.HtmlControls.HtmlInputButton P1Reset;

protected System.Web.UI.HtmlControls.HtmlInputButton P2Reset;

protected System.Web.UI.HtmlControls.HtmlInputButton P3Reset;


private void Page_Load(object sender, System.EventArgs e)

{

if(!Page.IsPostBack)

{

Step1.Font.Bold = true;

}


}


public void Next_Click(object sender, System.EventArgs e)

{

switch(sender.Parent.ID)

{

case "Page1": Page1.Visible = False;

Step1.Font.Bold = False;

Page2.Visible = True;

Step2.Font.Bold = True;

break;

case "Page2": Page2.Visible = False;

Step2.Font.Bold = False;

Page3.Visible = True;

Step3.Font.Bold = True;

ReviewFName.Text &= FirstName.Text;

ReviewMName.Text &= MiddleName.Text;

ReviewLName.Text &= LastName.Text;

ReviewEmail.Text &= Email.Text;

ReviewAddress.Text &= Address.Text;

ReviewCity.Text &= City.Text;

ReviewState.Text &= State.Text;

ReviewZip.Text &= Zip.Text;

break;

}

}



public void Previous_Click(object sender, System.EventArgs e)

{

switch(sender.Page.ID)

{


case "Page2":

Page2.Visible = False;

Step2.Font.Bold = False;

Page1.Visible = True;

Step1.Font.Bold = True;

break;

case "Page3":

Page3.Visible = False;

Step3.Font.Bold = False;

Page2.Visible = True;

Step2.Font.Bold = True;

break;


}

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}


/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}



----- Original Message -----
From: "wobbles" <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Wednesday, January 07, 2004 3:42 PM
Subject: Re: VB to C sharp anyone can point out which is the equivalent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top