Solved

C#2

Posted on 2012-03-17
2
297 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 500 total points
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now