嘿大家好,我是一個完整的新手到ASP .NET編程。我試圖獲得一個簡單的腳本運行,它從兩個文本框中獲取字符串輸入,將它們轉換爲整數,並檢查該過程是否成功發生,然後將這兩個文本框插入頁面的文本框中。編譯器錯誤消息:CS1026:)預計 - C#.Net,罰款VB.Net
我可以讓它在VB.Net中工作,但我學習ASP.Net的原因是在工作中創建一個應用程序,它必須使用C#.Net。有人可以幫助我爲什麼這個工程在VB中,而不是C#?代碼如下,錯誤消息是: 說明:編譯服務此請求所需資源時發生錯誤。請查看以下具體的錯誤細節並適當修改您的源代碼。
Compiler Error Message: CS1026:) expected
Source Error:
Line 1: <%@ Page Language="C#" %>
Line 2:
Line 3: Sub btnConvert_Click(sender As Object, e As EventArgs)
Line 4: Try
Line 5: lblToInt1.Text = cint(txtValue1.Text)
<%@ 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>
我知道這似乎很明顯,但VB是不同於C#。您將需要將代碼更改爲C#才能使用。你不能改變它的工作語言。 – Steve 2011-01-24 11:49:54