Simple code - convert from VB.net to c#.net (web dev)

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

Hello,

Anyone know how to do the following in c# - using inline codeblocks?

<% If Request.Form("Name") = "Gary" Then %>

<asp:RequiredFieldValidator ID="GarysValidation" ErrorMessage="Gary, you
have chosen the wrong option<BR>" ControlToValidate="Name" Display="Dynamic"
runat="server"></asp:RequiredFieldValidator>

<% End If %>

Thanks for any help,

Regards,

Gary.
 
There's many free online C#/VB.NET code converters you can use to do that.

Here's a few, in no particular order.
Check them out...and see which one you like best.

http://www.carlosag.net/Tools/CodeTranslator/default.aspx
http://www.dotnettaxi.com/Tools/Converter.aspx
http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx
http://www.eggheadcafe.com/articles/cstovbweb/converter.aspx



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
(via Instant C#)
<%
if (Request.Form["Name"] == "Gary")
{
%>

<asp:RequiredFieldValidator ID="GarysValidation" ErrorMessage="Gary, you
have chosen the wrong option<BR>" ControlToValidate="Name" Display="Dynamic"
runat="server"></asp:RequiredFieldValidator>

<%
}
%>

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
 
The on-line converters won't convert in-line asp.net code Juan. (see my
other reply for the conversion).
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
 
Maybe that should be a tip not to use ASP syntax in ASP.NET.
Would changing the control's visibility depending on the selected option
be better ?


Could you elaborate? You spotted I am a classic ASP coder, finding the
transition to .NET a challenge.

I do have a code behind file in place, and I am slowly reading about Life
Cycle etc, but at this moment I am unsure how best to approach this
particular task.

G.
 
re:
I am unsure how best to approach this particular task

Maybe adding some server code would help...

<script language = "VB" runat="server">

Sub Get_Input (Src As Object, Args As EventArgs)
Output.Text = "You entered '" & Name.Text & "'"
End Sub

</script>

<form Runat="Server">

<asp:TextBox id="Name" Runat="Server"/>

<asp:Button Text="Submit" OnClick="Get_Input" Runat="Server"/>

<asp:RequiredFieldValidator Runat="Server"
ID="GarysValidation"
ControlToValidate="Name"
ErrorMessage="Gary, you need to enter a value."
Display="Dynamic"
SetFocusOnError="True"/>

<asp:Label id="Output" Runat="Server"/>

</form>

I'm assuming that what you are aiming for is not having an empty textbox or,
if there is one, that the user can be informed without disruption.

Is that what you are aiming for ?

The above code will display the message "Gary, you need to enter a value."
if the textbox is empty, or will display whatever the user wrote into the Name textbox.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
re:


Maybe adding some server code would help...

<script language = "VB" runat="server">

Sub Get_Input (Src As Object, Args As EventArgs)
Output.Text = "You entered '" & Name.Text & "'"
End Sub

</script>

<form Runat="Server">

<asp:TextBox id="Name" Runat="Server"/>

<asp:Button Text="Submit" OnClick="Get_Input" Runat="Server"/>

<asp:RequiredFieldValidator Runat="Server"
ID="GarysValidation"
ControlToValidate="Name"
ErrorMessage="Gary, you need to enter a value."
Display="Dynamic"
SetFocusOnError="True"/>

<asp:Label id="Output" Runat="Server"/>

</form>

I'm assuming that what you are aiming for is not having an empty textbox or,
if there is one, that the user can be informed without disruption.

Is that what you are aiming for ?

The above code will display the message "Gary, you need to enter a value."
if the textbox is empty, or will display whatever the user wrote into theName textbox.

Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/
===================================


I would like to ask that, if i have a VB.net file, is there any free
tools for me to convert it into C#.net?

Thx a lot!!!
 
Here's three free online tools:

http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx

http://www.carlosag.net/Tools/CodeTranslator/default.aspx

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

And a free IDE which has a converter:
http://www.icsharpcode.net/OpenSource/SD/Download/




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================

I would like to ask that, if i have a VB.net file, is there any free
tools for me to convert it into C#.net?

Thx a lot!!!
 

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

Back
Top