Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
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.
1 Answer
- ?Lv 68 years agoFavorite Answer
Follow the path of your number 1 and number 2
double number1 = 0.0; <---- Number1=0.0
string txtRate = "";
double number2 = 0.0;<----- Number2=0.0
Label lblSalary = FindControl("lblSalary") as Label;
string strlblSalary = lblSalary.Text;
double number3 = number1 * number2; <---- number1*number2=0*0
number1 = Convert.ToDouble(txtAnnualHours); <--now your telling it what number1 is AFTER you calculate.
number2 = Convert.ToDouble(txtRate);<----same here
number3 = Convert.ToDouble(lblSalary); <--- and then your overwriting what you calculated anyway using what ever the label says? instead of setting the label to the calclated value.which i assume is what you would want.
Never played around with c# thou.. so youre on your own there.. that just stands out to me as screwy.