By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 972 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

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

P: n/a
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>
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Wed, 7 Jan 2004 15:06:04 -0600, "Hai Nguyen"
<ha******@neo.tamu.edu> wrote:
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


It will be something along the lines of:

private void next_click(object sender, System.EventArgs e) {

switch (sender.Parent.ID) {
case x:
//code
break;
case y:
//code
break;
case n:
//code
break;
default:
//code
break;
}

....

}
Nov 15 '05 #2

P: n/a
>
Translate these two lines to C sharp:

Sub Next_Click(Sender As Object, e As EventArgs)
Select Case Sender.Parent.ID
Below is a sample "translation":

private void Next_Click(object Sender, System.EventArgs e)
{
switch (Sender.ParentID)
{
case "Page1":
// ...
break;
case "Page2":
// ...
break;
default:
// ...
break;
}
}

Cheers,
Christian T. [MSFT]
Visual Studio Update Team

- Please do not reply to this email directly. This email is for newsgroup
purposes only.
================================================== =======================
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included script samples are subject to the terms specified
at http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which
they originated.
================================================== =======================

--------------------From: "Hai Nguyen" <ha******@neo.tamu.edu>
Subject: VB to C sharp anyone can point out which is the equivalent
Date: Wed, 7 Jan 2004 15:06:04 -0600
Lines: 248
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <uW**************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: eslnt01.tamu.edu 165.91.212.76
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftng xa09.phx.gbl!TK2MSFTNGP08.
phx.gbl!TK2MSFTNGP11.phx.gblXref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.csharp:210149
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

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 equivalentobject 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>


Nov 15 '05 #3

P: n/a
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" <no***************************@killspam.hotmail.co m>
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

On Wed, 7 Jan 2004 15:06:04 -0600, "Hai Nguyen"
<ha******@neo.tamu.edu> wrote:
I'm learning C sharp and do not like vb much. I'm creatiing a wepage usingpanel to test myself. I tried to use these code below, which is written inVB, 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 equivalentobject 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
It will be something along the lines of:

private void next_click(object sender, System.EventArgs e) {

switch (sender.Parent.ID) {
case x:
//code
break;
case y:
//code
break;
case n:
//code
break;
default:
//code
break;
}

...

}

"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message
news:uW**************@TK2MSFTNGP11.phx.gbl... 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>

Nov 15 '05 #4

P: n/a
I've seen from your original post that Sender.Parent.ID seems to
return a string - which I missed originally.

So it needs to be:
case "Page 1":

rather than:
case x:
Hope you have better luck...


On Wed, 7 Jan 2004 20:39:44 -0600, "Hai Nguyen"
<ha******@neo.tamu.edu> wrote:
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" <no***************************@killspam.hotmail.co m>
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

On Wed, 7 Jan 2004 15:06:04 -0600, "Hai Nguyen"
<ha******@neo.tamu.edu> wrote:
>I'm learning C sharp and do not like vb much. I'm creatiing a wepageusing >panel to test myself. I tried to use these code below, which is writtenin >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 theequivalent >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
>
>


It will be something along the lines of:

private void next_click(object sender, System.EventArgs e) {

switch (sender.Parent.ID) {
case x:
//code
break;
case y:
//code
break;
case n:
//code
break;
default:
//code
break;
}

...

}

"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message
news:uW**************@TK2MSFTNGP11.phx.gbl...
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>


Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.