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

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

Guest

(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
 
G

Guest

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
 
J

Juan T. Llibre

re:
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 ?
 
G

Gary

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

Juan T. Llibre

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

yyshirman

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 the Name textbox.


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

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top