Monday, March 26, 2012

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

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/CodeT...or/default.aspx
http://www.dotnettaxi.com/Tools/Converter.aspx
http://www.developerfusion.co.uk/ut...vbtocsharp.aspx
http://www.eggheadcafe.com/articles.../converter.aspx
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"Gary" <g@.nospam.comwrote in message news:Ogo7KdUPHHA.140@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

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.


(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

"Gary" wrote:

Quote:

Originally Posted by

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


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

"Juan T. Llibre" wrote:

Quote:

Originally Posted by

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/CodeT...or/default.aspx
http://www.dotnettaxi.com/Tools/Converter.aspx
http://www.developerfusion.co.uk/ut...vbtocsharp.aspx
http://www.eggheadcafe.com/articles.../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/
===================================
"Gary" <g@.nospam.comwrote in message news:Ogo7KdUPHHA.140@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

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.


>
>
>


re:

Quote:

Originally Posted by

The on-line converters won't convert in-line asp.net code Juan.


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 ?

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"David Anton" <DavidAnton@.discussions.microsoft.comwrote in message
news:166F99D6-5D9D-4CA2-BBBD-4971B64B373C@.microsoft.com...

Quote:

Originally Posted by

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


Quote:

Originally Posted by

"Juan T. Llibre" wrote:
>

Quote:

Originally Posted by

>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/CodeT...or/default.aspx
>http://www.dotnettaxi.com/Tools/Converter.aspx
>http://www.developerfusion.co.uk/ut...vbtocsharp.aspx
>http://www.eggheadcafe.com/articles.../converter.aspx
>>
>>
>>
>Juan T. Llibre, asp.net MVP
>asp.net faq : http://asp.net.do/faq/
>foros de asp.net, en espaol : http://asp.net.do/foros/
>===================================
>"Gary" <g@.nospam.comwrote in message news:Ogo7KdUPHHA.140@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

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.


>>
>>
>>


"Juan T. Llibre" <nomailreplies@.nowhere.comwrote in message
news:OU%23Oz5XPHHA.4260@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Quote:

Originally Posted by

>The on-line converters won't convert in-line asp.net code Juan.


>
Maybe that should be a tip not to use ASP syntax in ASP.NET.


Absolutely!
Maybe that should be a tip not to use ASP syntax in ASP.NET.

Quote:

Originally Posted by

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:

Quote:

Originally Posted by

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 espaol : http://asp.net.do/foros/
===================================
"Gary" <g@.nospam.comwrote in message news:eiXaJ1ZPHHA.4244@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

Quote:

Originally Posted by

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


On 1月22日, 上午7時20分, "Juan T.Llibre" <nomailrepl...@.nowhere.comwrote:

Quote:

Originally Posted by

re:
>

Quote:

Originally Posted by

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 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/
===================================
>
"Gary" <g...@.nospam.comwrote in messagenews:eiXaJ1ZPHHA.4244@.TK2MSFTNGP04.phx.gbl. ..

Quote:

Originally Posted by

Quote:

Originally Posted by

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 ?


>

Quote:

Originally Posted by

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


>

Quote:

Originally Posted by

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.


>

Quote:

Originally Posted by

G.


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!!!
<yyshirman@.gmail.comwrote in message
news:1170753596.902466.298390@.q2g2000cwa.googlegro ups.com...

Quote:

Originally Posted by

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?


Loads of 'em - do a Google search...
Here's three free online tools:

http://www.developerfusion.co.uk/ut...vbtocsharp.aspx
http://www.carlosag.net/Tools/CodeT...or/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 espaol : http://asp.net.do/foros/
===================================
<yyshirman@.gmail.comwrote in message news:1170753596.902466.298390@.q2g2000cwa.googlegro ups.com...

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

0 comments:

Post a Comment