
Untitled
By: a guest on
Jul 4th, 2012 | syntax:
None | size: 1.65 KB | hits: 15 | expires: Never
Compiler Error Message: CS1026: ) expected - C# .Net, fine in VB .Net
<%@ Page Language="C#" %>
<script runat="server">
Sub btnConvert_Click(sender As Object, e As EventArgs)
Try
lblToInt1.Text = cint(txtValue1.Text)
Catch
lblToInt1.Text = "Could not convert to Integer"
End Try
Try
lblToInt2.Text = cint(txtValue2.Text)
Catch
lblToInt2.Text = "Could not convert to Integer"
End Try
lblToInt3.Text = cint(txtValue1.Text)+cint(txtValue2.Text)
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
Text Value 1:
<asp:TextBox id="txtValue1" runat="server"></asp:TextBox>
</p>
<p>
Text Value 2:
<asp:TextBox id="txtValue2" runat="server"></asp:TextBox>
<asp:Button id="btnConvert" onclick="btnConvert_Click" runat="server" Text="Do it!"></asp:Button>
</p>
<p>
Convert to Integer produces 1:
<asp:Label id="lblToInt1" runat="server"></asp:Label>
</p>
<p>
Convert to Integer produces 2:
<asp:Label id="lblToInt2" runat="server"></asp:Label>
</p>
<p>
Total of your 2 numbers:
<asp:Textbox id="lblToInt3" runat="server"></asp:Textbox>
</p>
</form>
</body>
</html>
void btnConvert_Click(object sender, EventArgs e)
{
try
{
lblToInt1.Text = int.Parse(txtValue1.Text).ToString();
}
catch //this could be replaced by a single call to int.TryParse
{
lblToInt1.Text = "Could not convert to Integer";
}
// etc, etc...
}