Here is my issue. I have an assignment where I have to write a simple ASPX page the lets the users input into 3 text boxes and click a calculate button which will return the result of how many items are requested. Here’s what I have. The line
is suppose to save the users input into the ID txtPlateQty and in the C# code below, which is a separate file in visual studio 2010, I want to take the users input and convert it into an int for calculations. The issue is in the C# file the “Convert.ToInt32(txtPlateQty.Text); does not recognize the variable “txtPlateQty” as if it’s out of scope. This is a assignment for a class and my professor has and identical example and his works while mine does not. If anyone could shed some light onto what is causing this issue I would be very grateful.
<%@ 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>
Your CashRegister.aspx.cs code behind should look some thing like:
Your CashRegister.aspx markup should look like:
Web.config