Solved

C#2

Posted on 2012-03-17
2
302 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 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