Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C#2

Posted on 2012-03-17
2
Medium Priority
?
308 Views
Last Modified: 2012-03-17
Dear sirs:  I am in need of some help here.  I have created the html for this Employee Salary calculator.  I know that I have to create an paycheck.html and a Default.aspx.  I want the submit button to calculate the input for the hours and pay rate.  Can someone help me? I am new to this ASP.NET and Visual Basic.  I am trying to do this on my own just need a little guidance.

<!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>
        <title>Paycheck</title>
    <script language="C#" type="text/css">

        function Text1_onclick() {

        }

        function Text2_onclick() {

        }
        void Submit1_onclick(object sender, EventArgs e) {
             if (Text1.Text.Length < 1)
                MessageBox.Show("Please Enter a value in Hours Field ");
             else if (Text2.Text.Length < 1)
                MessageBox.Show("Please Enter a value in Pay Rate Field");
             else if (
             else if
             {
                double hours = Convert.ToDouble(textBox1.Text);
                double rate = Convert.ToDouble(textBox2.Text);
                MessageBox.Show("Your Gross Pay is $" + ("hours - 40 * rate * 1.5");
            }
      </script>
</head>
<body>
    <form action="Default.aspx" method="post">
    <p>Enter Hours Worked:<input id="Text1" type="text" onclick="return Text1_onclick()" /></p>
    <p>Enter Pay Rate:<input id="Text2" type="text" onclick="return Text2_onclick()" /></p>
    <p><input id="Submit1" type="submit" value="submit" onclick="return Submit1_onclick()" /></p>
    </form>
</body>

</html>
0
Comment
Question by:assaultkitty
2 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 2000 total points
ID: 37733630
Some of the same problems still exist from your other question on this assignment.

Your text boxes and button cannot be seen by the server without runat="server" attribute.

To get the script to run, it needs to have a runat="server" in the script tag.

Your button would need an onServerClick="Submit1_onclick" not onclick="return Submit1_onclick()"

Standard input textboxes do not have a Text property. Use Text1.Value instead of Text1.Text.

Remove the onclick attributes from textboxes and the code. You don't need them.

Remove the type="text/css" from the script tag.

I suggest you move your script block outside the head section as it has nothing to do with the HTML markup.

MessageBox is something you use in Windows forms, not in asp.net web forms. Print your results and error messages to a label or a javascript alert box.

There are syntax errors in your script. Standard C# format for a i/else if/else block is:

if(condition1)
{
}
else if (condition2)
{
}
else
{
}
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 37733635
your <script> tag should speicfy type="text/C#"

you say "I am new to this ASP.NET and Visual Basic", but the code is written in C#.

what will happen if the user enters a letter in either text box?

the result message box

MessageBox.Show("Your Gross Pay is $" + ("hours - 40 * rate * 1.5");

should show:

MessageBox.Show("Your Gross Pay is $" + hours - 40 * rate * 1.5;


or better:

MessageBox.Show(string.Format("Your Gross Pay is $ {0}" ,hours - 40 * rate * 1.5));

AW
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question