這是我的問題。我有一個任務,我必須編寫一個簡單的ASPX頁面,讓用戶輸入3個文本框並單擊一個計算按鈕,該按鈕將返回請求的項目數。這是我的。 行假設將用戶輸入保存到ID txtPlateQty和下面的C#代碼中,這是Visual Studio 2010中的一個單獨文件,我希望將用戶輸入並將其轉換爲用於計算的int值。問題出在C#文件中,「Convert.ToInt32(txtPlateQty.Text);不能識別變量」txtPlateQty「,就好像它超出了範圍。這是一個類的任務,我的教授擁有相同的例子和他的作品而我卻沒有。如果有人可以提供一些線索到是什麼原因造成這個問題,我將非常感激。文件在Visual Studio的ASPX文件輸入中沒有正確讀取
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CashRegister.aspx.cs" Inherits="ProjectX.CashRegister" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtPlateQty" runat="server"></asp:TextBox>
<asp:TextBox ID="txtSomethingElse1" runat="server"></asp:TextBox>
<asp:TextBox ID="txtSomethingElse2" runat="server"></asp:TextBox>
<asp:Button ID="btnCalculate" runat="server" Text="Button" onclick="btnCalculate_Click" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class CashRegister : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCalculate_Click(object sender, EventArgs e)
{
int plateQty = Convert.ToInt32(txtPlateQty.Text);
int somethingElse1 = Convert.ToInt32(txtSomethingElse1.Text);
int somethingElse2 = Convert.ToInt32(txtSomethingElse2.Text);
}
}
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation defaultLanguage="C#" debug="true"></compilation>
</system.web>
</configuration>
我想你將不得不張貼更多的代碼。嘗試發佈整個aspx和代碼隱藏。 – swannee 2012-02-23 02:08:54
您收到錯誤嗎?你怎麼知道它不被識別? – Brettski 2012-02-23 02:11:09
您需要按4個空格縮進代碼。選擇代碼並按下Control-K。 – 2012-02-23 02:22:46