Can anyone help me with my C#/HTML problem?
So I'm taking a Web Application Programming class and our first assignment is building a form that calculates salary by multiplying the hourly rate and total hours worked. It's done in C#(Visual Studio 2008) with an HTML form. Now the code as it stands doesn't return a build error, however it won't 1) calculate the numbers I put in and 2) display the results via the submit button.
Now before I was getting errors such as "'string' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'string' could be found(are you missing a using directive or an assembly reference?)" because I was putting 'Text' at the end of a line "txtAnnualHours.Text".
an earlier error was something like "'lblSalary' does not exist in the current context".
Some of the code you see is because I've been searching for similar problems online and tried to adapt their solutions into my code so the problems don't occur...but I know I'm doing something wrong. The question is...what?
Bear in mind I'm following an ilab's directions.
below is the code I have.
<script runat="server">
protected void salary_onclick(object sender, EventArgs e) {
string txtAnnualHours = "";
double number1 = 0.0;
string txtRate = "";
double number2 = 0.0;
Label lblSalary = FindControl("lblSalary") as Label;
string strlblSalary = lblSalary.Text;
double number3 = number1 * number2;
number1 = Convert.ToDouble(txtAnnualHours);
number2 = Convert.ToDouble(txtRate);
number3 = Convert.ToDouble(lblSalary);
txtAnnualHours = number1.ToString();
txtRate = number2.ToString();
lblSalary.Text = number3.ToString();
}
// ]]>
</script>
</head>
<body>
<form = "annual" method="post" style=" height: 104px">
<label for= "Annual Hours">Annual Hours:</label>
<input type="text" name="Annual Hours" id="txtAnnualHours" maxlength="50" />
<label for= "Rate">
Rate:</label>
<input type="text" name="Rate" id="txtRate" maxlength="50" />
<input type="button" id="salary" value="Calculate Salary" onclick="salary_onclick(object sender, EventArgs e)" />
<label for="calculation" id="lblSalary">$</label></form>
I'm sure it's tempting...but please resist the urge to be a jerk when responding.
Thank you in advance.